diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index cbf0a29..de31c44 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -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() diff --git a/django_lostplaces/lostplaces/templates/explorer/profile_update.html b/django_lostplaces/lostplaces/templates/explorer/profile_update.html index 0da5ec8..6e8c491 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile_update.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile_update.html @@ -7,7 +7,7 @@ {% block maincontent %} -
+
{% trans 'Edit Explorer profile' %} {% csrf_token %} diff --git a/django_lostplaces/lostplaces/views/place_views.py b/django_lostplaces/lostplaces/views/place_views.py index c96726b..c069dc0 100644 --- a/django_lostplaces/lostplaces/views/place_views.py +++ b/django_lostplaces/lostplaces/views/place_views.py @@ -150,4 +150,5 @@ class PlaceUnfavoriteView(IsAuthenticatedMixin, View): else: return redirect( reverse_lazy('place_detail', kwargs={'pk': place.pk}) - ) \ No newline at end of file + ) + \ No newline at end of file