Delete profile_image on user_deletion.
This commit is contained in:
parent
cc59254ba4
commit
3eaa186b66
@ -68,9 +68,24 @@ class Explorer(models.Model):
|
|||||||
|
|
||||||
@receiver(post_save, sender=User)
|
@receiver(post_save, sender=User)
|
||||||
def create_user_profile(sender, instance, created, **kwargs):
|
def create_user_profile(sender, instance, created, **kwargs):
|
||||||
|
"""
|
||||||
|
Delete Explorer profile when User gets deleted.
|
||||||
|
Deletion on profile_pic update is not necessary, as it gets
|
||||||
|
simply overwritten.
|
||||||
|
"""
|
||||||
if created:
|
if created:
|
||||||
Explorer.objects.create(user=instance)
|
Explorer.objects.create(user=instance)
|
||||||
|
|
||||||
|
def auto_delete_file_on_delete(sender, instance, **kwargs):
|
||||||
|
"""
|
||||||
|
Deletes file (including thumbnails) from filesystem
|
||||||
|
when corresponding `profile_image` object is deleted.
|
||||||
|
"""
|
||||||
|
if instance.profile_image:
|
||||||
|
# Get and delete all files and thumbnails from instance
|
||||||
|
thumbmanager = get_thumbnailer(instance.profile_image)
|
||||||
|
thumbmanager.delete(save=False)
|
||||||
|
|
||||||
@receiver(post_save, sender=User)
|
@receiver(post_save, sender=User)
|
||||||
def save_user_profile(sender, instance, **kwargs):
|
def save_user_profile(sender, instance, **kwargs):
|
||||||
instance.explorer.save()
|
instance.explorer.save()
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
{% block maincontent %}
|
{% block maincontent %}
|
||||||
|
|
||||||
<form class="LP-Form" method="POST">
|
<form class="LP-Form" method="POST" enctype="multipart/form-data">
|
||||||
<fieldset class="LP-Form__Fieldset">
|
<fieldset class="LP-Form__Fieldset">
|
||||||
<legend class="LP-Form__Legend">{% trans 'Edit Explorer profile' %}</legend>
|
<legend class="LP-Form__Legend">{% trans 'Edit Explorer profile' %}</legend>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
@ -151,3 +151,4 @@ class PlaceUnfavoriteView(IsAuthenticatedMixin, View):
|
|||||||
return redirect(
|
return redirect(
|
||||||
reverse_lazy('place_detail', kwargs={'pk': place.pk})
|
reverse_lazy('place_detail', kwargs={'pk': place.pk})
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user