From 99899235ce18ac73649948a6dce8ad73f3e22675 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 18 Apr 2011 20:50:31 +0200 Subject: [PATCH] cleanup --- pandora/archive/models.py | 16 +++++++++++++++- pandora/item/models.py | 17 +++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 568f2956..7cd67ea7 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -9,6 +9,7 @@ import time from django.db import models from django.contrib.auth.models import User from django.conf import settings +from django.db.models.signals import pre_delete from ox.django import fields import ox @@ -334,6 +335,14 @@ class File(models.Model): ext = '.unknown' return name + ext +def delete_file(sender, **kwargs): + f = kwargs['instance'] + if f.video: + f.video.delete() + if f.data: + f.data.delete() +pre_delete.connect(delete_file, sender=File) + class Volume(models.Model): class Meta: @@ -348,7 +357,6 @@ class Volume(models.Model): def __unicode__(self): return u"%s's %s"% (self.user, self.name) - class Instance(models.Model): class Meta: @@ -408,3 +416,9 @@ class Frame(models.Model): def __unicode__(self): return u'%s/%s' % (self.file, self.position) + +def delete_frame(sender, **kwargs): + f = kwargs['instance'] + if f.frame: + f.frame.delete() +pre_delete.connect(delete_frame, sender=Frame) diff --git a/pandora/item/models.py b/pandora/item/models.py index 9501c3ce..105ecc43 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -6,6 +6,7 @@ from datetime import datetime import os.path import subprocess from glob import glob +import shutil import uuid import unicodedata @@ -15,6 +16,7 @@ from django.core.files.base import ContentFile from django.utils import simplejson as json from django.conf import settings from django.contrib.auth.models import User, Group +from django.db.models.signals import pre_delete import ox from ox.django import fields @@ -238,12 +240,11 @@ class Item(models.Model): if update_poster: tasks.update_poster.delay(self.itemId) + def delete_files(self): + shutil.rmtree(self.path('')) + def delete(self, *args, **kwargs): - self.delete_poster() - for f in glob("%s*"%self.timeline_prefix): - os.unlink(f) - for f in glob("%sstrip*"%self.timeline_prefix[:-8]): - os.unlink(f) + self.delete_files() super(Item, self).delete(*args, **kwargs) def merge_with(self, other): @@ -594,7 +595,7 @@ class Item(models.Model): def main_videos(self): #FIXME: needs to check if more than one user has main files and only # take from "higher" user - videos = self.files.filter(is_main=True, is_video=True, available=True) + videos = self.files.filter(is_main=True, is_video=True, available=True).order_by('part') if videos.count()>0: first = videos[0] user = first.instances.all()[0].volume.user @@ -807,6 +808,10 @@ class Item(models.Model): return icon return None +def delete_item(sender, **kwargs): + i = kwargs['instance'] + i.delete_files() +pre_delete.connect(delete_item, sender=Item) config = site_config()