This commit is contained in:
j 2011-04-18 20:50:31 +02:00
parent 3dfe2e8c75
commit 99899235ce
2 changed files with 26 additions and 7 deletions

View file

@ -9,6 +9,7 @@ import time
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from django.db.models.signals import pre_delete
from ox.django import fields from ox.django import fields
import ox import ox
@ -334,6 +335,14 @@ class File(models.Model):
ext = '.unknown' ext = '.unknown'
return name + ext 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 Volume(models.Model):
class Meta: class Meta:
@ -348,7 +357,6 @@ class Volume(models.Model):
def __unicode__(self): def __unicode__(self):
return u"%s's %s"% (self.user, self.name) return u"%s's %s"% (self.user, self.name)
class Instance(models.Model): class Instance(models.Model):
class Meta: class Meta:
@ -408,3 +416,9 @@ class Frame(models.Model):
def __unicode__(self): def __unicode__(self):
return u'%s/%s' % (self.file, self.position) 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)

View file

@ -6,6 +6,7 @@ from datetime import datetime
import os.path import os.path
import subprocess import subprocess
from glob import glob from glob import glob
import shutil
import uuid import uuid
import unicodedata import unicodedata
@ -15,6 +16,7 @@ from django.core.files.base import ContentFile
from django.utils import simplejson as json from django.utils import simplejson as json
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.db.models.signals import pre_delete
import ox import ox
from ox.django import fields from ox.django import fields
@ -238,12 +240,11 @@ class Item(models.Model):
if update_poster: if update_poster:
tasks.update_poster.delay(self.itemId) tasks.update_poster.delay(self.itemId)
def delete_files(self):
shutil.rmtree(self.path(''))
def delete(self, *args, **kwargs): def delete(self, *args, **kwargs):
self.delete_poster() self.delete_files()
for f in glob("%s*"%self.timeline_prefix):
os.unlink(f)
for f in glob("%sstrip*"%self.timeline_prefix[:-8]):
os.unlink(f)
super(Item, self).delete(*args, **kwargs) super(Item, self).delete(*args, **kwargs)
def merge_with(self, other): def merge_with(self, other):
@ -594,7 +595,7 @@ class Item(models.Model):
def main_videos(self): def main_videos(self):
#FIXME: needs to check if more than one user has main files and only #FIXME: needs to check if more than one user has main files and only
# take from "higher" user # 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: if videos.count()>0:
first = videos[0] first = videos[0]
user = first.instances.all()[0].volume.user user = first.instances.all()[0].volume.user
@ -807,6 +808,10 @@ class Item(models.Model):
return icon return icon
return None return None
def delete_item(sender, **kwargs):
i = kwargs['instance']
i.delete_files()
pre_delete.connect(delete_item, sender=Item)
config = site_config() config = site_config()