From 04fd0429233bd15fe3cf046cef578d593778c12d Mon Sep 17 00:00:00 2001 From: Weitian LI Date: Mon, 28 Apr 2014 13:40:19 +0800 Subject: * included archive urls * moved 'file_cleanup' function to extra.py --- account/extra.py | 16 ++++++++++++++++ account/models.py | 17 +---------------- django_skaschool/urls.py | 2 ++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/account/extra.py b/account/extra.py index 6ff19b2..8f034c9 100644 --- a/account/extra.py +++ b/account/extra.py @@ -86,3 +86,19 @@ class OverwriteStorage(FileSystemStorage): return name +### delete files associated with model FileField +# Pre-delete signal function for deleting files a model +# https://djangosnippets.org/snippets/2820/ +def file_cleanup(sender, instance, *args, **kwargs): + """ + Deletes the file(s) associated with a model instance. The model + is not saved after deletion of the file(s) since this is meant + to be used with the pre_delete signal. + """ + for field_name, _ in instance.__dict__.iteritems(): + field = getattr(instance, field_name) + if (issubclass(field.__class__, FieldFile) and field.name): + # pass False so FileField does not save the model + field.delete(save=False) + + diff --git a/account/models.py b/account/models.py index b42a8d1..9c3f44e 100644 --- a/account/models.py +++ b/account/models.py @@ -14,7 +14,7 @@ from django.utils.translation import ugettext_lazy as _ from django.db.models.signals import pre_delete from registration.signals import user_registered, user_activated -from account.extra import ContentTypeRestrictedFileField, OverwriteStorage +from account.extra import ContentTypeRestrictedFileField, OverwriteStorage, file_cleanup import os @@ -251,21 +251,6 @@ def login_on_activation(sender, user, request, **kwargs): user_activated.connect(login_on_activation) -### delete files associated with model FileField -# Pre-delete signal function for deleting files a model -# https://djangosnippets.org/snippets/2820/ -def file_cleanup(sender, instance, *args, **kwargs): - """ - Deletes the file(s) associated with a model instance. The model - is not saved after deletion of the file(s) since this is meant - to be used with the pre_delete signal. - """ - for field_name, _ in instance.__dict__.iteritems(): - field = getattr(instance, field_name) - if (issubclass(field.__class__, FieldFile) and field.name): - # pass False so FileField does not save the model - field.delete(save=False) - ### connect to signal and sender pre_delete.connect(file_cleanup, sender=UserProfile) pre_delete.connect(file_cleanup, sender=UserFile) diff --git a/django_skaschool/urls.py b/django_skaschool/urls.py index 24bd989..7830463 100644 --- a/django_skaschool/urls.py +++ b/django_skaschool/urls.py @@ -21,6 +21,8 @@ urlpatterns = patterns('', url(r'^page/', include('page.urls')), # app 'notice' url(r'^notice/', include('notice.urls')), + # app 'archive' + url(r'^archive/', include('archive.urls')), ) ## django-registration -- cgit v1.2.2