Changed easy_thumbnails image/thumb deletion. Now working.
This commit is contained in:
parent
011a58f6b3
commit
9f369456d5
@ -11,7 +11,7 @@ import uuid
|
|||||||
|
|
||||||
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.db.models.signals import post_save
|
from django.db.models.signals import post_save, pre_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
@ -75,6 +75,25 @@ def create_user_profile(sender, instance, created, **kwargs):
|
|||||||
def save_user_profile(sender, instance, **kwargs):
|
def save_user_profile(sender, instance, **kwargs):
|
||||||
instance.explorer.save()
|
instance.explorer.save()
|
||||||
|
|
||||||
|
@receiver(pre_save, sender=Explorer)
|
||||||
|
def auto_delete_file_on_change(sender, instance, **kwargs):
|
||||||
|
"""
|
||||||
|
Deletes old file from filesystem
|
||||||
|
when corresponding `Explorer` object is updated
|
||||||
|
with new file.
|
||||||
|
"""
|
||||||
|
if not instance.pk:
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
old_file = Explorer.objects.get(pk=instance.pk).profile_image
|
||||||
|
except Explorer.DoesNotExist:
|
||||||
|
return False
|
||||||
|
print("Deleting:", old_file)
|
||||||
|
new_file = instance.profile_image
|
||||||
|
if not old_file == new_file:
|
||||||
|
old_file.delete(save=False)
|
||||||
|
|
||||||
class Voucher(Expireable):
|
class Voucher(Expireable):
|
||||||
"""
|
"""
|
||||||
Vouchers are authorization tokens to allow the registration of new users.
|
Vouchers are authorization tokens to allow the registration of new users.
|
||||||
|
@ -104,7 +104,6 @@ class PlaceImage (PlaceAsset):
|
|||||||
|
|
||||||
return 'Image ' + str(self.pk)
|
return 'Image ' + str(self.pk)
|
||||||
|
|
||||||
|
|
||||||
# These two auto-delete files from filesystem when they are unneeded:
|
# These two auto-delete files from filesystem when they are unneeded:
|
||||||
|
|
||||||
@receiver(post_delete, sender=PlaceImage)
|
@receiver(post_delete, sender=PlaceImage)
|
||||||
@ -118,7 +117,6 @@ def auto_delete_file_on_delete(sender, instance, **kwargs):
|
|||||||
thumbmanager = get_thumbnailer(instance.filename)
|
thumbmanager = get_thumbnailer(instance.filename)
|
||||||
thumbmanager.delete(save=False)
|
thumbmanager.delete(save=False)
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_save, sender=PlaceImage)
|
@receiver(pre_save, sender=PlaceImage)
|
||||||
def auto_delete_file_on_change(sender, instance, **kwargs):
|
def auto_delete_file_on_change(sender, instance, **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -137,5 +135,4 @@ def auto_delete_file_on_change(sender, instance, **kwargs):
|
|||||||
# No need to delete thumbnails, as they will be overwritten on regeneration.
|
# No need to delete thumbnails, as they will be overwritten on regeneration.
|
||||||
new_file = instance.filename
|
new_file = instance.filename
|
||||||
if not old_file == new_file:
|
if not old_file == new_file:
|
||||||
if os.path.isfile(old_file.path):
|
old_file.delete(save=False)
|
||||||
os.remove(old_file.path)
|
|
||||||
|
@ -56,6 +56,7 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View):
|
|||||||
return render(request, 'explorer/profile_update.html', context)
|
return render(request, 'explorer/profile_update.html', context)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
print(request.POST)
|
||||||
explorer_user_change_form = ExplorerUserChangeForm(
|
explorer_user_change_form = ExplorerUserChangeForm(
|
||||||
request.POST,
|
request.POST,
|
||||||
instance=request.user
|
instance=request.user
|
||||||
@ -70,6 +71,8 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View):
|
|||||||
explorer_user_change_form.save()
|
explorer_user_change_form.save()
|
||||||
explorer_change_form.save()
|
explorer_change_form.save()
|
||||||
|
|
||||||
|
print(explorer_change_form.cleaned_data)
|
||||||
|
|
||||||
messages.success(
|
messages.success(
|
||||||
self.request,
|
self.request,
|
||||||
_('Successfully updated Explorer profile')
|
_('Successfully updated Explorer profile')
|
||||||
|
Loading…
Reference in New Issue
Block a user