Delete profile_image on user_deletion.

This commit is contained in:
Marcus Scholz 2020-12-25 12:53:52 +01:00
parent cc59254ba4
commit 3eaa186b66
3 changed files with 18 additions and 2 deletions

View File

@ -68,9 +68,24 @@ class Explorer(models.Model):
@receiver(post_save, sender=User)
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:
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)
def save_user_profile(sender, instance, **kwargs):
instance.explorer.save()

View File

@ -7,7 +7,7 @@
{% block maincontent %}
<form class="LP-Form" method="POST">
<form class="LP-Form" method="POST" enctype="multipart/form-data">
<fieldset class="LP-Form__Fieldset">
<legend class="LP-Form__Legend">{% trans 'Edit Explorer profile' %}</legend>
{% csrf_token %}

View File

@ -150,4 +150,5 @@ class PlaceUnfavoriteView(IsAuthenticatedMixin, View):
else:
return redirect(
reverse_lazy('place_detail', kwargs={'pk': place.pk})
)
)