From 981c440ce3d92ceab479728598839958022847b0 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 15:13:31 +0100 Subject: [PATCH 01/36] Fix voucher class description --- django_lostplaces/lostplaces/models/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index 16b53da..cbdfb66 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -41,11 +41,13 @@ def save_user_profile(sender, instance, **kwargs): class Voucher(Expireable): """ - Vouchers are authorization to created_when = models.DateTimeField(auto_now_add=True) - expires_when = models.DateTimeField()kens to allow the registration of new users. + Vouchers are authorization tokens to allow the registration of new users. A voucher has a code, a creation and a deletion date, which are all positional. Creation date is being set automatically during voucher creation. + + created_when = models.DateTimeField(auto_now_add=True) + expires_when = models.DateTimeField() """ code = models.CharField(unique=True, max_length=30) From cbbda88850123edda2b697e585a26ffac537541d Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 15:13:40 +0100 Subject: [PATCH 02/36] Remove debug output. --- django_lostplaces/lostplaces/views/explorer_views.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index 3fee7d3..0197faa 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -33,13 +33,9 @@ class ExplorerProfileView(IsAuthenticatedMixin, View): asset_count += objects.count() context['asset_count'] = asset_count - - print(context['assets']) - + return render( request=request, template_name='explorer/profile.html', context=context ) - - \ No newline at end of file From d04e9864194d251802ddb2cd000a98aecd8be502 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 15:33:46 +0100 Subject: [PATCH 03/36] Added display of name and e-mail. --- .../lostplaces/templates/explorer/profile.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html index 4cf7948..aaf425b 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -14,6 +14,22 @@
+ + + + + + + +
+ {% trans 'Name' %} + + {{explorer.user.first_name}} {{explorer.user.last_name}} +
+ {% trans 'E-Mail' %} + + {{explorer.user.email}} +
{% trans 'Joined' %} From 07fe1bc3ca81defd4c03512470e5ea3dda9ddb19 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 17:23:20 +0100 Subject: [PATCH 04/36] Rename place_image_path function. --- django_lostplaces/lostplaces/models/place.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/django_lostplaces/lostplaces/models/place.py b/django_lostplaces/lostplaces/models/place.py index 588696f..8fc6790 100644 --- a/django_lostplaces/lostplaces/models/place.py +++ b/django_lostplaces/lostplaces/models/place.py @@ -49,10 +49,10 @@ class Place(Submittable, Taggable, Mapable): return self.name -def generate_image_upload_path(instance, filename): +def generate_place_image_filename(instance, filename): """ - Callback for generating path for uploaded images. - Returns filename as: place_pk-placename{-rnd_string}.jpg + Callback for generating filename for uploaded place images. + Returns filename as: place_pk-placename{-number}.jpg """ return 'places/' + str(instance.place.pk) + '-' + str(instance.place.name) + '.' + filename.split('.')[-1] @@ -84,7 +84,7 @@ class PlaceImage (PlaceAsset): verbose_name=_('Description'), ) filename = ThumbnailerImageField( - upload_to=generate_image_upload_path, + upload_to=generate_place_image_filename, resize_source=dict(size=(2560, 2560), sharpen=True), verbose_name=_('Filename(s)'), From 35e0f912feac24a4b02af4649d4b76adda8626c2 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 17:24:02 +0100 Subject: [PATCH 05/36] Add profile_pic --- .../locale/de/LC_MESSAGES/django.po | 68 ++++++++++++++++--- django_lostplaces/lostplaces/models/models.py | 23 ++++++- 2 files changed, 81 insertions(+), 10 deletions(-) diff --git a/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po b/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po index e0bc7c9..37ba12c 100644 --- a/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po +++ b/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-10-11 21:53+0200\n" +"POT-Creation-Date: 2020-12-24 16:29+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Commander1024 \n" "Language-Team: LANGUAGE \n" @@ -30,7 +30,7 @@ msgstr "Ungültiger Voucher" msgid "Expired voucher" msgstr "Abgelaufener Voucher" -#: models/abstract_models.py:29 +#: models/abstract_models.py:29 templates/explorer/profile.html:19 msgid "Name" msgstr "Name" @@ -74,6 +74,16 @@ msgstr "Adresse (URL)" msgid "link text" msgstr "Linktext" +#: models/models.py:46 +#, fuzzy +#| msgid "Filename(s)" +msgid "Filename" +msgstr "Dateiname(n)" + +#: models/models.py:47 +msgid "Optional profile pic for display in explorer profile" +msgstr "" + #: models/place.py:21 msgid "Location" msgstr "Ort" @@ -110,38 +120,78 @@ msgstr "Du wirst in 5 Sekunden weitergeleitet" msgid "Go Back" msgstr "Zurück" +#: templates/explorer/profile.html:27 +msgid "E-Mail" +msgstr "" + +#: templates/explorer/profile.html:35 +msgid "Joined" +msgstr "" + +#: templates/explorer/profile.html:43 +#, fuzzy +#| msgid "All Places" +msgid "Places" +msgstr "Alle Places" + +#: templates/explorer/profile.html:51 +msgid "Place Assets" +msgstr "" + +#: templates/explorer/profile.html:65 +#, fuzzy +#| msgid "Image(s) submitted successfully" +msgid "Places submitted by" +msgstr "Bild(er) erfolgreich hinzugefügt" + +#: templates/explorer/profile.html:82 +#, fuzzy +#| msgid "Image(s) submitted successfully" +msgid "Images submitted by" +msgstr "Bild(er) erfolgreich hinzugefügt" + +#: templates/explorer/profile.html:104 +#, fuzzy +#| msgid "Photo album link submitted" +msgid "Photo albums submitted by" +msgstr "Fotoalbum-Link hinzugefügt" + #: templates/global.html:32 msgid "Logout" msgstr "Ausloggen" -#: templates/global.html:34 +#: templates/global.html:33 +msgid "Profile" +msgstr "" + +#: templates/global.html:35 msgid "Admin" msgstr "Admin" -#: templates/global.html:39 templates/registration/login.html:4 +#: templates/global.html:40 templates/registration/login.html:4 #: templates/registration/login.html:10 templates/registration/login.html:23 msgid "Login" msgstr "Anmelden" -#: templates/global.html:40 templates/registration/login.html:29 +#: templates/global.html:41 templates/registration/login.html:29 #: templates/signup.html:6 templates/signup.html:12 templates/signup.html:41 msgid "Sign up" msgstr "Registrieren" -#: templates/global.html:50 templates/home.html:10 +#: templates/global.html:51 templates/home.html:10 msgid "Home" msgstr "Startseite" -#: templates/global.html:51 +#: templates/global.html:52 msgid "UrBex Codex" msgstr "UrBex Codex" -#: templates/global.html:56 templates/place/place_create.html:5 +#: templates/global.html:57 templates/place/place_create.html:5 #: templates/place/place_create.html:10 msgid "Create place" msgstr "Place erstellen" -#: templates/global.html:57 +#: templates/global.html:58 msgid "All places" msgstr "Alle Places" diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index cbdfb66..5e9f910 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -6,15 +6,28 @@ database. ''' +import os import uuid from django.db import models from django.contrib.auth.models import User from django.db.models.signals import post_save from django.dispatch import receiver +from django.utils.translation import ugettext_lazy as _ from lostplaces.models.abstract_models import Expireable +from easy_thumbnails.fields import ThumbnailerImageField +from easy_thumbnails.files import get_thumbnailer + +def generate_profile_image_filename(instance, filename): + """ + Callback for generating filename for uploaded explorer profile images. + Returns filename as: explorer_pk-username.jpg + """ + + return 'explorers/' + str(instance.explorer.pk) + '-' + str(instance.explorer.username) + '.' + filename.split('.')[-1] + class Explorer(models.Model): """ Profile that is linked to the a User. @@ -26,6 +39,15 @@ class Explorer(models.Model): on_delete=models.CASCADE, related_name='explorer' ) + profile_image = ThumbnailerImageField( + blank=True, + null=True, + upload_to=generate_profile_image_filename, + resize_source=dict(size=(400, 400), + sharpen=True), + verbose_name=_('Profile image'), + help_text=_('Optional profile pic for display in explorer profile') + ) def __str__(self): return self.user.username @@ -58,4 +80,3 @@ class Voucher(Expireable): def __str__(self): return "Voucher " + str(self.code) - From 734d09df909a069d54cba2616ad681bcdc351dc1 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 17:59:05 +0100 Subject: [PATCH 06/36] Add favorite_places to user profile page. --- .../lostplaces/templates/explorer/profile.html | 16 ++++++++++++++++ .../lostplaces/views/explorer_views.py | 1 + 2 files changed, 17 insertions(+) diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html index 0e49976..e5f99d7 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -60,6 +60,22 @@ +
+
+

{% trans 'Favorite places' %}

+
    + {% for place in favorite_places %} +
  • + {% include 'partials/place_teaser.html' with place=place extended=True %} +
  • + {% endfor %} +
+ + {% include 'partials/nav/pagination.html' %} + +
+
+

{% trans 'Places submitted by' %} {{explorer.user.username}}

diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index 0197faa..5053477 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -23,6 +23,7 @@ class ExplorerProfileView(IsAuthenticatedMixin, View): 'explorer': explorer, 'place_count': place_count, 'place_list': place_list, + 'favorite_places': explorer.favorite_places.all(), 'assets': {} } From 0c38ca9a15471f6266eb06d3419ab4d368ca2310 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 18:03:07 +0100 Subject: [PATCH 07/36] Revert changes, as it was redundant. --- django_lostplaces/lostplaces/views/explorer_views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index 5053477..0197faa 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -23,7 +23,6 @@ class ExplorerProfileView(IsAuthenticatedMixin, View): 'explorer': explorer, 'place_count': place_count, 'place_list': place_list, - 'favorite_places': explorer.favorite_places.all(), 'assets': {} } From a9013d9673b0a0844bb96597696e2967de5a3b6d Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 18:03:31 +0100 Subject: [PATCH 08/36] Pulled favorite_places out of explorer instance. --- django_lostplaces/lostplaces/templates/explorer/profile.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html index e5f99d7..dfee163 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -64,7 +64,7 @@

{% trans 'Favorite places' %}

    - {% for place in favorite_places %} + {% for place in explorer.favorite_places.all %}
  • {% include 'partials/place_teaser.html' with place=place extended=True %}
  • From d5827b2006663231c0a01a9a205db62f8a269ee7 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 18:14:40 +0100 Subject: [PATCH 09/36] Fixed filename generation. --- django_lostplaces/lostplaces/models/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index d577405..5b9b986 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -27,7 +27,7 @@ def generate_profile_image_filename(instance, filename): Returns filename as: explorer_pk-username.jpg """ - return 'explorers/' + str(instance.explorer.pk) + '-' + str(instance.explorer.username) + '.' + filename.split('.')[-1] + return 'explorers/' + str(instance.user.pk) + '-' + str(instance.user.username) + '.' + filename.split('.')[-1] class Explorer(models.Model): """ From 2022a924c4af7aea80eb197cd20ac8f8b2cc7b48 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 18:30:29 +0100 Subject: [PATCH 10/36] Added output of profile image to profile_page. --- .../lostplaces/templates/explorer/profile.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html index dfee163..774a65b 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -14,6 +14,12 @@
+ + {% if explorer.profile_image %} +
+ +
+ {% endif %}
{% trans 'Name' %} From 88bffbef8eebc6bd77e87e7cece9cbe45c99a984 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 18:53:30 +0100 Subject: [PATCH 11/36] Added Explorer bio / description field. --- django_lostplaces/lostplaces/models/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index 5b9b986..7f3f6c4 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -40,6 +40,12 @@ class Explorer(models.Model): on_delete=models.CASCADE, related_name='explorer' ) + bio = models.TextField( + blank=True, + null=True, + verbose_name=_('Biography / Description'), + help_text=_('Describe yourself, your preferences, etc. in a few sentences.') + ) profile_image = ThumbnailerImageField( blank=True, null=True, @@ -49,7 +55,6 @@ class Explorer(models.Model): verbose_name=_('Profile image'), help_text=_('Optional profile pic for display in explorer profile') ) - favorite_places = models.ManyToManyField( Place, related_name='favorite_places', From b0396f52237aa83cf017282185fe51023ce372fb Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 19:04:04 +0100 Subject: [PATCH 12/36] Added bio and email link to profile template. --- .../lostplaces/templates/explorer/profile.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html index 774a65b..d829cbf 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -7,11 +7,16 @@ {% block maincontent %}
+
+

Bio

+

{{explorer.bio}}

+

{{explorer.user.username}}

+
@@ -33,7 +38,9 @@ {% trans 'E-Mail' %} From 07ea2f164c648cdae27fd6ab5a48f31be5622cd6 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 19:13:55 +0100 Subject: [PATCH 13/36] Name and E-Mail is only shown when populated in profile. --- .../lostplaces/templates/explorer/profile.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html index d829cbf..18c39cb 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -26,15 +26,18 @@ {% endif %} + {% if explorer.user.first_name %} + {% endif %} - + {% endif %} {% if explorer.user.email %} + + +
- {{explorer.user.email}} + + {{explorer.user.email}} +
{% trans 'Name' %} {{explorer.user.first_name}} {{explorer.user.last_name}}
+ {% if explorer.user.email %} + {% trans 'E-Mail' %} @@ -42,6 +45,7 @@ {{explorer.user.email}}
From a7c8848fd6ca7c68fad62af62bb444b3a5e7a49b Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 19:36:41 +0100 Subject: [PATCH 14/36] Allow user to provide his first and last name on registration. --- django_lostplaces/lostplaces/forms.py | 4 ++-- django_lostplaces/lostplaces/templates/signup.html | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/django_lostplaces/lostplaces/forms.py b/django_lostplaces/lostplaces/forms.py index 7cd51e3..4ccdff2 100644 --- a/django_lostplaces/lostplaces/forms.py +++ b/django_lostplaces/lostplaces/forms.py @@ -13,7 +13,7 @@ from lostplaces.models import Place, PlaceImage, Voucher class ExplorerCreationForm(UserCreationForm): class Meta: model = User - fields = ('username', 'email') + fields = ('username', 'email', 'first_name', 'last_name') voucher = forms.CharField( max_length=30, help_text=_('The Voucher you got from an administrator') @@ -38,7 +38,7 @@ class ExplorerCreationForm(UserCreationForm): class ExplorerChangeForm(UserChangeForm): class Meta: model = User - fields = ('username', 'email') + fields = ('username', 'email', 'first_name', 'last_name') class PlaceForm(forms.ModelForm): class Meta: diff --git a/django_lostplaces/lostplaces/templates/signup.html b/django_lostplaces/lostplaces/templates/signup.html index c3a3949..895784b 100644 --- a/django_lostplaces/lostplaces/templates/signup.html +++ b/django_lostplaces/lostplaces/templates/signup.html @@ -19,6 +19,14 @@ {% include 'partials/form/inputField.html' with field=form.email %} +
+
+ {% include 'partials/form/inputField.html' with field=form.first_name %} +
+
+ {% include 'partials/form/inputField.html' with field=form.last_name %} +
+
From 648264c9fc31719347bc5a69d9e2df98f0b84e8b Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 20:13:06 +0100 Subject: [PATCH 15/36] Remove obsoleted imports. --- django_lostplaces/lostplaces/admin.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/django_lostplaces/lostplaces/admin.py b/django_lostplaces/lostplaces/admin.py index c6f6280..ec58dac 100644 --- a/django_lostplaces/lostplaces/admin.py +++ b/django_lostplaces/lostplaces/admin.py @@ -9,8 +9,6 @@ from django.contrib.auth.admin import UserAdmin from django.utils import timezone from lostplaces.models import * -from lostplaces.forms import ExplorerCreationForm, ExplorerChangeForm - # Register your models here. class VoucherAdmin(admin.ModelAdmin): From 3a20a60f0569d455dd579e3def4cc18984fa854c Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 20:22:33 +0100 Subject: [PATCH 16/36] Remove obsolete ExplorerChangeForm. --- django_lostplaces/lostplaces/forms.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/django_lostplaces/lostplaces/forms.py b/django_lostplaces/lostplaces/forms.py index 4ccdff2..fd0e423 100644 --- a/django_lostplaces/lostplaces/forms.py +++ b/django_lostplaces/lostplaces/forms.py @@ -35,11 +35,6 @@ class ExplorerCreationForm(UserCreationForm): fetched_voucher.delete() return True -class ExplorerChangeForm(UserChangeForm): - class Meta: - model = User - fields = ('username', 'email', 'first_name', 'last_name') - class PlaceForm(forms.ModelForm): class Meta: model = Place From 3855fb28d75ab3544058a6783ea06bb3422156e7 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 20:25:05 +0100 Subject: [PATCH 17/36] Rename ExplorerCreationForm to SignupVoucherForm. --- django_lostplaces/lostplaces/forms.py | 2 +- .../lostplaces/tests/forms/test_explorer_forms.py | 10 +++++----- django_lostplaces/lostplaces/views/views.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/django_lostplaces/lostplaces/forms.py b/django_lostplaces/lostplaces/forms.py index fd0e423..9e622b2 100644 --- a/django_lostplaces/lostplaces/forms.py +++ b/django_lostplaces/lostplaces/forms.py @@ -10,7 +10,7 @@ from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ from lostplaces.models import Place, PlaceImage, Voucher -class ExplorerCreationForm(UserCreationForm): +class SignupVoucherForm(UserCreationForm): class Meta: model = User fields = ('username', 'email', 'first_name', 'last_name') diff --git a/django_lostplaces/lostplaces/tests/forms/test_explorer_forms.py b/django_lostplaces/lostplaces/tests/forms/test_explorer_forms.py index 89b6986..a2a0d25 100644 --- a/django_lostplaces/lostplaces/tests/forms/test_explorer_forms.py +++ b/django_lostplaces/lostplaces/tests/forms/test_explorer_forms.py @@ -4,15 +4,15 @@ from django import forms from django.utils import timezone from lostplaces.tests.forms import FormTestCase -from lostplaces.forms import ExplorerCreationForm +from lostplaces.forms import SignupVoucherForm from lostplaces.models.models import Voucher -class ExplorerCreationFormTestCase(FormTestCase): +class SignupVoucherFormTestCase(FormTestCase): """ This test case only tests for the voucher since all other aspects don't realy matter to this project and are already tested by django """ - form = ExplorerCreationForm + form = SignupVoucherForm @classmethod def setUpTestData(cls): @@ -37,7 +37,7 @@ class ExplorerCreationFormTestCase(FormTestCase): ) def test_validation_valid(self): - form = ExplorerCreationForm(self.post_data) + form = SignupVoucherForm(self.post_data) self.assertTrue( form.is_valid(), msg='Expecting the %s to validate' % ( @@ -49,7 +49,7 @@ class ExplorerCreationFormTestCase(FormTestCase): self.post_data = { 'voucher': 'Imanotacode123' } - form = ExplorerCreationForm(self.post_data) + form = SignupVoucherForm(self.post_data) self.assertFalse( form.is_valid(), msg='Expecting the %s to not validate' % ( diff --git a/django_lostplaces/lostplaces/views/views.py b/django_lostplaces/lostplaces/views/views.py index 03982ad..21320b8 100644 --- a/django_lostplaces/lostplaces/views/views.py +++ b/django_lostplaces/lostplaces/views/views.py @@ -11,7 +11,7 @@ from django.shortcuts import render, redirect, get_object_or_404 from django.http import HttpResponseForbidden from django.utils.translation import ugettext_lazy as _ -from lostplaces.forms import ExplorerCreationForm, TagSubmitForm +from lostplaces.forms import SignupVoucherForm, TagSubmitForm from lostplaces.models import Place, PhotoAlbum from lostplaces.views.base_views import IsAuthenticatedMixin @@ -23,7 +23,7 @@ from lostplaces.views.base_views import ( from taggit.models import Tag class SignUpView(SuccessMessageMixin, CreateView): - form_class = ExplorerCreationForm + form_class = SignupVoucherForm success_url = reverse_lazy('login') template_name = 'signup.html' success_message = _('User created') From 53f89caef58a261a362c74d23498946df41d5e02 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 20:31:52 +0100 Subject: [PATCH 18/36] Added a ModelForm to change profile details. --- django_lostplaces/lostplaces/forms.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/forms.py b/django_lostplaces/lostplaces/forms.py index 9e622b2..89a95ab 100644 --- a/django_lostplaces/lostplaces/forms.py +++ b/django_lostplaces/lostplaces/forms.py @@ -8,7 +8,7 @@ from django.db import models from django.contrib.auth.forms import UserCreationForm, UserChangeForm from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ -from lostplaces.models import Place, PlaceImage, Voucher +from lostplaces.models import Place, PlaceImage, Voucher, Explorer class SignupVoucherForm(UserCreationForm): class Meta: @@ -35,6 +35,12 @@ class SignupVoucherForm(UserCreationForm): fetched_voucher.delete() return True +class ProfileChangeForm(forms.ModelForm): + class Meta: + model = Explorer + fields = '__all__' + exclude = ['user', 'favorite_places'] + class PlaceForm(forms.ModelForm): class Meta: model = Place From 30f259fb4d2a08828b1441979b56b4863eaf6e28 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 24 Dec 2020 23:51:40 +0100 Subject: [PATCH 19/36] WIP-commit of translations to test against fuzzy detection. --- .../locale/de/LC_MESSAGES/django.po | 80 ++++++++++++------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po b/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po index 37ba12c..736e5da 100644 --- a/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po +++ b/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-12-24 16:29+0100\n" +"POT-Creation-Date: 2020-12-24 23:39+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Commander1024 \n" "Language-Team: LANGUAGE \n" @@ -30,7 +30,7 @@ msgstr "Ungültiger Voucher" msgid "Expired voucher" msgstr "Abgelaufener Voucher" -#: models/abstract_models.py:29 templates/explorer/profile.html:19 +#: models/abstract_models.py:29 templates/explorer/profile.html:31 msgid "Name" msgstr "Name" @@ -81,8 +81,16 @@ msgid "Filename" msgstr "Dateiname(n)" #: models/models.py:47 -msgid "Optional profile pic for display in explorer profile" -msgstr "" +msgid "Describe yourself, your preferences, etc. in a few sentences." +msgstr "Beschreibe Dich selbst, Deine Vorlieben, usw. in ein paar Sätzen." + +#: models/models.py:55 +msgid "Profile image" +msgstr "Profilbild" + +#: models/models.py:56 +msgid "Optional profile image for display in Explorer profile" +msgstr "Optionales Profilbind zur Anzeige im Explorerprofil" #: models/place.py:21 msgid "Location" @@ -120,41 +128,50 @@ msgstr "Du wirst in 5 Sekunden weitergeleitet" msgid "Go Back" msgstr "Zurück" -#: templates/explorer/profile.html:27 -msgid "E-Mail" -msgstr "" +#: templates/explorer/profile.html:41 +msgid "E-mail" +msgstr "E-Mail" -#: templates/explorer/profile.html:35 +#: templates/explorer/profile.html:52 msgid "Joined" -msgstr "" +msgstr "Beigetreten" -#: templates/explorer/profile.html:43 +#: templates/explorer/profile.html:60 #, fuzzy #| msgid "All Places" msgid "Places" msgstr "Alle Places" -#: templates/explorer/profile.html:51 +#: templates/explorer/profile.html:68 msgid "Place Assets" msgstr "" -#: templates/explorer/profile.html:65 -#, fuzzy -#| msgid "Image(s) submitted successfully" -msgid "Places submitted by" -msgstr "Bild(er) erfolgreich hinzugefügt" - #: templates/explorer/profile.html:82 -#, fuzzy -#| msgid "Image(s) submitted successfully" -msgid "Images submitted by" -msgstr "Bild(er) erfolgreich hinzugefügt" +msgid "Favorite places" +msgstr "Favoriten-Places" -#: templates/explorer/profile.html:104 -#, fuzzy -#| msgid "Photo album link submitted" +#: templates/explorer/profile.html:98 +msgid "Places submitted by" +msgstr "Places hinzugefügt von" + +#: templates/explorer/profile.html:113 +msgid "Images submitted by" +msgstr "Bilder hinzugefügt von" + +#: templates/explorer/profile.html:135 msgid "Photo albums submitted by" -msgstr "Fotoalbum-Link hinzugefügt" +msgstr "Fotoalben hinzugefügt von" + +#: templates/explorer/profile_update.html:6 +#: templates/explorer/profile_update.html:12 +msgid "Edit Explorer profile" +msgstr "Bearbeite Explorerprofil" + +#: templates/explorer/profile_update.html:49 templates/global.html:41 +#: templates/registration/login.html:29 templates/signup.html:6 +#: templates/signup.html:12 templates/signup.html:49 +msgid "Sign up" +msgstr "Registrieren" #: templates/global.html:32 msgid "Logout" @@ -173,11 +190,6 @@ msgstr "Admin" msgid "Login" msgstr "Anmelden" -#: templates/global.html:41 templates/registration/login.html:29 -#: templates/signup.html:6 templates/signup.html:12 templates/signup.html:41 -msgid "Sign up" -msgstr "Registrieren" - #: templates/global.html:51 templates/home.html:10 msgid "Home" msgstr "Startseite" @@ -244,6 +256,14 @@ msgstr "Abschicken" msgid "Cancel" msgstr "Abbrechen" +#: templates/partials/icons/place_favorite.html:6 +msgid "Remove from favorites" +msgstr "Aus den Favoriten entfernen" + +#: templates/partials/icons/place_favorite.html:10 +msgid "Save as favorite" +msgstr "In den Favoriten speichern" + #: templates/partials/nav/footer.html:64 msgid "Made by" msgstr "Erstellt von" From 4f0182fc3ed29a83a26b2c37720a612d08a3c093 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 01:28:23 +0100 Subject: [PATCH 20/36] Minor textual changes for consistency. --- django_lostplaces/lostplaces/templates/explorer/profile.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html index 18c39cb..77db9a1 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -38,7 +38,7 @@
- {% trans 'E-Mail' %} + {% trans 'E-mail' %} @@ -65,7 +65,7 @@
- {% trans 'Place Assets'%} + {% trans 'Place assets'%} {{asset_count}} From 7359bf5fab18a95b1c0d4dc6c115e91c2395f3f0 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 01:31:01 +0100 Subject: [PATCH 21/36] ExplorerChangeForms, with deactivated username field. --- django_lostplaces/lostplaces/forms.py | 14 ++++- .../templates/explorer/profile_update.html | 55 +++++++++++++++++++ django_lostplaces/lostplaces/urls.py | 6 +- .../lostplaces/views/explorer_views.py | 13 +++++ 4 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 django_lostplaces/lostplaces/templates/explorer/profile_update.html diff --git a/django_lostplaces/lostplaces/forms.py b/django_lostplaces/lostplaces/forms.py index 89a95ab..491bcd0 100644 --- a/django_lostplaces/lostplaces/forms.py +++ b/django_lostplaces/lostplaces/forms.py @@ -35,7 +35,19 @@ class SignupVoucherForm(UserCreationForm): fetched_voucher.delete() return True -class ProfileChangeForm(forms.ModelForm): +class ExplorerUserChangeForm(UserChangeForm): + class Meta: + model = User + fields = [ 'username', 'first_name', 'last_name', 'email' ] + password = None + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['username'].required = False + self.fields['username'].help_text = None + self.fields['username'].widget.attrs['disabled'] = 'disabled' + +class ExplorerChangeForm(forms.ModelForm): class Meta: model = Explorer fields = '__all__' diff --git a/django_lostplaces/lostplaces/templates/explorer/profile_update.html b/django_lostplaces/lostplaces/templates/explorer/profile_update.html new file mode 100644 index 0000000..0da5ec8 --- /dev/null +++ b/django_lostplaces/lostplaces/templates/explorer/profile_update.html @@ -0,0 +1,55 @@ +{% extends 'global.html'%} +{% load static %} +{% load i18n %} +{% load widget_tweaks %} + +# {% block title %}{% trans 'Edit Explorer profile' %}{% endblock %} + +{% block maincontent %} + +
+
+ {% trans 'Edit Explorer profile' %} + {% csrf_token %} +
+
+ {% include 'partials/form/inputField.html' with field=explorer_user_change_form.username %} +
+
+ {% include 'partials/form/inputField.html' with field=explorer_user_change_form.email %} +
+
+
+
+ {% include 'partials/form/inputField.html' with field=explorer_user_change_form.first_name %} +
+
+ {% include 'partials/form/inputField.html' with field=explorer_user_change_form.last_name %} +
+
+ +
+
+ {% include 'partials/form/inputField.html' with field=explorer_change_form.bio %} +
+
+ +
+ {% if explorer_image_url %} +
+ +
+ {% endif %} +
+ {% include 'partials/form/inputField.html' with field=explorer_change_form.profile_image %} +
+
+ + {% trans 'Update' as action %} +
+ {% include 'partials/form/submit.html' with referrer=request.META.HTTP_REFERER action=action %} +
+
+
+ +{% endblock maincontent %} diff --git a/django_lostplaces/lostplaces/urls.py b/django_lostplaces/lostplaces/urls.py index 0e38282..bcfb646 100644 --- a/django_lostplaces/lostplaces/urls.py +++ b/django_lostplaces/lostplaces/urls.py @@ -18,7 +18,8 @@ from lostplaces.views import ( PlaceImageCreateView, PlaceImageDeleteView, FlatView, - ExplorerProfileView + ExplorerProfileView, + ExplorerProfileUpdateView ) urlpatterns = [ @@ -39,9 +40,8 @@ urlpatterns = [ path('place/tag/delete//', PlaceTagDeleteView.as_view(), name='place_tag_delete'), path('explorer//', ExplorerProfileView.as_view(), name='explorer_profile'), + path('explorer/update/', ExplorerProfileUpdateView.as_view(), name='explorer_profile_update'), path('explorer/favorite//', PlaceFavoriteView.as_view(), name='place_favorite'), path('explorer/unfavorite//', PlaceUnfavoriteView.as_view(), name='place_unfavorite') - - ] diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index 0197faa..9faf5b1 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -12,6 +12,7 @@ from lostplaces.common import get_all_subclasses from lostplaces.views.base_views import IsAuthenticatedMixin from lostplaces.models.models import Explorer from lostplaces.models.place import Place, PlaceAsset +from lostplaces.forms import ExplorerChangeForm, ExplorerUserChangeForm class ExplorerProfileView(IsAuthenticatedMixin, View): def get(self, request, explorer_id): @@ -39,3 +40,15 @@ class ExplorerProfileView(IsAuthenticatedMixin, View): template_name='explorer/profile.html', context=context ) + +class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): + success_message = '' + permission_denied_message = '' + + def get(self, request, *args, **kwargs): + context = { + 'explorer_image_url': request.user.explorer.profile_image.url, + 'explorer_user_change_form': ExplorerUserChangeForm(instance=request.user), + 'explorer_change_form': ExplorerChangeForm(instance=request.user.explorer) + } + return render(request, 'explorer/profile_update.html', context) From c71fe4cf2dc6ff39cd343bf164648050357528a8 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 01:31:43 +0100 Subject: [PATCH 22/36] Added new translations (de) --- .../locale/de/LC_MESSAGES/django.po | 35 ++++++++++--------- django_lostplaces/lostplaces/models/models.py | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po b/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po index 736e5da..c6ce18c 100644 --- a/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po +++ b/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-12-24 23:39+0100\n" +"POT-Creation-Date: 2020-12-25 01:22+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Commander1024 \n" "Language-Team: LANGUAGE \n" @@ -75,10 +75,8 @@ msgid "link text" msgstr "Linktext" #: models/models.py:46 -#, fuzzy -#| msgid "Filename(s)" -msgid "Filename" -msgstr "Dateiname(n)" +msgid "Biography / Description" +msgstr "Beschreibung" #: models/models.py:47 msgid "Describe yourself, your preferences, etc. in a few sentences." @@ -143,7 +141,7 @@ msgid "Places" msgstr "Alle Places" #: templates/explorer/profile.html:68 -msgid "Place Assets" +msgid "Place assets" msgstr "" #: templates/explorer/profile.html:82 @@ -165,13 +163,12 @@ msgstr "Fotoalben hinzugefügt von" #: templates/explorer/profile_update.html:6 #: templates/explorer/profile_update.html:12 msgid "Edit Explorer profile" -msgstr "Bearbeite Explorerprofil" +msgstr "Explorerprofil bearbeiten" -#: templates/explorer/profile_update.html:49 templates/global.html:41 -#: templates/registration/login.html:29 templates/signup.html:6 -#: templates/signup.html:12 templates/signup.html:49 -msgid "Sign up" -msgstr "Registrieren" +#: templates/explorer/profile_update.html:48 +#: templates/place/place_update.html:42 +msgid "Update" +msgstr "Aktualisieren" #: templates/global.html:32 msgid "Logout" @@ -190,6 +187,11 @@ msgstr "Admin" msgid "Login" msgstr "Anmelden" +#: templates/global.html:41 templates/registration/login.html:29 +#: templates/signup.html:6 templates/signup.html:12 templates/signup.html:49 +msgid "Sign up" +msgstr "Registrieren" + #: templates/global.html:51 templates/home.html:10 msgid "Home" msgstr "Startseite" @@ -388,10 +390,6 @@ msgstr "Alle Places" msgid "Our lost places" msgstr "Unsere Lost Places" -#: templates/place/place_update.html:42 -msgid "Update" -msgstr "Aktualisieren" - #: templates/place_image/place_image_create.html:7 msgid "Submit images to a place" msgstr "Bilder zu einem Place hinzufügen" @@ -455,3 +453,8 @@ msgstr "Fotoalbum-Link gelöscht" #: views/views.py:60 msgid "You are not allowed to edit this photo album link" msgstr "Du darfst diesen Fotoalbum-Link nicht bearbeiten" + +#, fuzzy +#~| msgid "Filename(s)" +#~ msgid "Filename" +#~ msgstr "Dateiname(n)" diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index 7f3f6c4..453a936 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -53,7 +53,7 @@ class Explorer(models.Model): resize_source=dict(size=(400, 400), sharpen=True), verbose_name=_('Profile image'), - help_text=_('Optional profile pic for display in explorer profile') + help_text=_('Optional profile image for display in Explorer profile') ) favorite_places = models.ManyToManyField( Place, From 14ca45d111f572b17b9033b907d5e595f786905a Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 01:36:14 +0100 Subject: [PATCH 23/36] Comments for customizations of UserChangeForm. --- django_lostplaces/lostplaces/forms.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/django_lostplaces/lostplaces/forms.py b/django_lostplaces/lostplaces/forms.py index 491bcd0..59cfccf 100644 --- a/django_lostplaces/lostplaces/forms.py +++ b/django_lostplaces/lostplaces/forms.py @@ -39,8 +39,10 @@ class ExplorerUserChangeForm(UserChangeForm): class Meta: model = User fields = [ 'username', 'first_name', 'last_name', 'email' ] + ''' Hide password hint.''' password = None + ''' Display username, but make it uneditable and not required. ''' def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['username'].required = False From 871acd1dcecd3c75c8729a933765718104075017 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 01:41:09 +0100 Subject: [PATCH 24/36] Improved class comment. --- django_lostplaces/lostplaces/models/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index 453a936..cbf0a29 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -31,8 +31,9 @@ def generate_profile_image_filename(instance, filename): class Explorer(models.Model): """ - Profile that is linked to the a User. + Profile that is linked to the Django user. Every user has a profile. + Provides additional attributes for user profile. """ user = models.OneToOneField( From b1aa4473e920ebb261655649f70ff326f433ec09 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 02:11:02 +0100 Subject: [PATCH 25/36] Added failsafe, if there is no profile_image. --- .../lostplaces/views/explorer_views.py | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index 9faf5b1..e3f8318 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -47,8 +47,35 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): def get(self, request, *args, **kwargs): context = { - 'explorer_image_url': request.user.explorer.profile_image.url, 'explorer_user_change_form': ExplorerUserChangeForm(instance=request.user), 'explorer_change_form': ExplorerChangeForm(instance=request.user.explorer) } + if request.user.explorer.profile_image: + context['explorer_image_url'] = request.user.explorer.profile_image.url return render(request, 'explorer/profile_update.html', context) + + def post(self, request, *args, **kwargs): + explorer_change_form = ExplorerChangeForm(request.POST) + + if place_form.is_valid(): + submitter = request.user.explorer + place = place_form.save(commit=False) + # Save logged in user as "submitted_by" + place.submitted_by = submitter + place.save() + + self.handle_place_images(request, place) + + messages.success( + self.request, + _('Successfully created place') + ) + return redirect(reverse_lazy('place_detail', kwargs={'pk': place.pk})) + + else: + # Usually the browser should have checked the form before sending. + messages.error( + self.request, + _('Please fill in all required fields.') + ) + return render(request, 'place/place_create.html', context={'form': place_form}) \ No newline at end of file From 17e71b71d4937da769468f54141b4aa1bb735bc1 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 08:04:35 +0100 Subject: [PATCH 26/36] Fix typo. --- django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po b/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po index c6ce18c..ca01b0c 100644 --- a/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po +++ b/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po @@ -88,7 +88,7 @@ msgstr "Profilbild" #: models/models.py:56 msgid "Optional profile image for display in Explorer profile" -msgstr "Optionales Profilbind zur Anzeige im Explorerprofil" +msgstr "Optionales Profilbild zur Anzeige im Explorerprofil" #: models/place.py:21 msgid "Location" From 0f5474c2d3c83479447c933a8644ce73de2aa52b Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 11:14:21 +0100 Subject: [PATCH 27/36] half-working :P --- .../lostplaces/views/explorer_views.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index e3f8318..6773f07 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -7,6 +7,7 @@ from django.utils.translation import ugettext_lazy as _ from django.shortcuts import render, redirect, get_object_or_404 from django.urls import reverse_lazy +from django.contrib import messages from lostplaces.common import get_all_subclasses from lostplaces.views.base_views import IsAuthenticatedMixin @@ -55,22 +56,21 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): return render(request, 'explorer/profile_update.html', context) def post(self, request, *args, **kwargs): - explorer_change_form = ExplorerChangeForm(request.POST) + explorer_user_change_form = ExplorerUserChangeForm(request.POST, instance=request.user) + explorer_change_form = ExplorerChangeForm(request.POST, instance=request.user.explorer) - if place_form.is_valid(): - submitter = request.user.explorer - place = place_form.save(commit=False) - # Save logged in user as "submitted_by" - place.submitted_by = submitter - place.save() + if explorer_change_form.is_valid() and explorer_user_change_form.is_valid(): + print(explorer_user_change_form) + explorer_user_change_form.save() + explorer_change_form.save() - self.handle_place_images(request, place) + #self.handle_place_images(request, explorer) messages.success( self.request, - _('Successfully created place') + _('Successfully updated Explorer profile') ) - return redirect(reverse_lazy('place_detail', kwargs={'pk': place.pk})) + return redirect(reverse_lazy('explorer_profile_update')) else: # Usually the browser should have checked the form before sending. @@ -78,4 +78,5 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): self.request, _('Please fill in all required fields.') ) - return render(request, 'place/place_create.html', context={'form': place_form}) \ No newline at end of file + return redirect(reverse_lazy('explorer_profile_update')) + \ No newline at end of file From 67a651771662511b0d5ad2a678e500c678aefa73 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 11:14:54 +0100 Subject: [PATCH 28/36] Comment improved. --- django_lostplaces/lostplaces/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/forms.py b/django_lostplaces/lostplaces/forms.py index 59cfccf..9629ff7 100644 --- a/django_lostplaces/lostplaces/forms.py +++ b/django_lostplaces/lostplaces/forms.py @@ -42,7 +42,7 @@ class ExplorerUserChangeForm(UserChangeForm): ''' Hide password hint.''' password = None - ''' Display username, but make it uneditable and not required. ''' + ''' Display username, but display it non-editable and not required. ''' def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['username'].required = False From cc59254ba462216ec14607720e5ee4922a02924c Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 12:24:09 +0100 Subject: [PATCH 29/36] Added clean_username function to validate form. --- django_lostplaces/lostplaces/forms.py | 8 ++++++++ django_lostplaces/lostplaces/views/explorer_views.py | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/forms.py b/django_lostplaces/lostplaces/forms.py index 9629ff7..4a590e1 100644 --- a/django_lostplaces/lostplaces/forms.py +++ b/django_lostplaces/lostplaces/forms.py @@ -48,6 +48,14 @@ class ExplorerUserChangeForm(UserChangeForm): self.fields['username'].required = False self.fields['username'].help_text = None self.fields['username'].widget.attrs['disabled'] = 'disabled' + + def clean_username(self): + # As shown in the above answer. + instance = getattr(self, 'instance', None) + if instance: + return instance.username + else: + return self.cleaned_data.get('username', None) class ExplorerChangeForm(forms.ModelForm): class Meta: diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index 6773f07..ccc10ff 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -60,7 +60,6 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): explorer_change_form = ExplorerChangeForm(request.POST, instance=request.user.explorer) if explorer_change_form.is_valid() and explorer_user_change_form.is_valid(): - print(explorer_user_change_form) explorer_user_change_form.save() explorer_change_form.save() From 3eaa186b666e49e17fea2fc9adeff0d4bfe60642 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 12:53:52 +0100 Subject: [PATCH 30/36] Delete profile_image on user_deletion. --- django_lostplaces/lostplaces/models/models.py | 15 +++++++++++++++ .../templates/explorer/profile_update.html | 2 +- django_lostplaces/lostplaces/views/place_views.py | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) 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 From 86cc7f23fed0b0f0bb0dc077fb751878513a4be1 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 13:19:34 +0100 Subject: [PATCH 31/36] description_fuckery. --- django_lostplaces/lostplaces/models/models.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index de31c44..1f163ca 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -65,27 +65,12 @@ class Explorer(models.Model): def __str__(self): return self.user.username - + @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() From 67ce6cb50b369cd5b33ae24dd2c946e979e40b7e Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 14:06:53 +0100 Subject: [PATCH 32/36] Added working explorer_profile_image upload. --- .../templates/explorer/profile_update.html | 1 - .../lostplaces/views/explorer_views.py | 17 ++++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/django_lostplaces/lostplaces/templates/explorer/profile_update.html b/django_lostplaces/lostplaces/templates/explorer/profile_update.html index 6e8c491..d852031 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile_update.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile_update.html @@ -1,5 +1,4 @@ {% extends 'global.html'%} -{% load static %} {% load i18n %} {% load widget_tweaks %} diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index ccc10ff..5e0a134 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -56,26 +56,29 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): return render(request, 'explorer/profile_update.html', context) def post(self, request, *args, **kwargs): - explorer_user_change_form = ExplorerUserChangeForm(request.POST, instance=request.user) - explorer_change_form = ExplorerChangeForm(request.POST, instance=request.user.explorer) + explorer_user_change_form = ExplorerUserChangeForm( + request.POST, + instance=request.user + ) + explorer_change_form = ExplorerChangeForm( + request.POST, + request.FILES, + instance=request.user.explorer + ) if explorer_change_form.is_valid() and explorer_user_change_form.is_valid(): explorer_user_change_form.save() explorer_change_form.save() - #self.handle_place_images(request, explorer) - messages.success( self.request, _('Successfully updated Explorer profile') ) - return redirect(reverse_lazy('explorer_profile_update')) - else: # Usually the browser should have checked the form before sending. messages.error( self.request, _('Please fill in all required fields.') ) - return redirect(reverse_lazy('explorer_profile_update')) + return redirect(reverse_lazy('explorer_profile_update')) \ No newline at end of file From 011a58f6b39c52354019b2bfbdb5c7bb1408a594 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 14:29:38 +0100 Subject: [PATCH 33/36] Use thumbnail in profile_update. --- .../lostplaces/templates/explorer/profile_update.html | 5 +++-- django_lostplaces/lostplaces/views/explorer_views.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/django_lostplaces/lostplaces/templates/explorer/profile_update.html b/django_lostplaces/lostplaces/templates/explorer/profile_update.html index d852031..9db8eca 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile_update.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile_update.html @@ -1,5 +1,6 @@ {% extends 'global.html'%} {% load i18n %} +{% load thumbnail %} {% load widget_tweaks %} # {% block title %}{% trans 'Edit Explorer profile' %}{% endblock %} @@ -34,9 +35,9 @@
- {% if explorer_image_url %} + {% if explorer_image %}
- +
{% endif %}
diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index 5e0a134..9d9ca3d 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -52,7 +52,7 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): 'explorer_change_form': ExplorerChangeForm(instance=request.user.explorer) } if request.user.explorer.profile_image: - context['explorer_image_url'] = request.user.explorer.profile_image.url + context['explorer_image'] = request.user.explorer.profile_image return render(request, 'explorer/profile_update.html', context) def post(self, request, *args, **kwargs): From 9f369456d5b3d13e003d68481fc6231b67fdb00e Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 15:42:02 +0100 Subject: [PATCH 34/36] Changed easy_thumbnails image/thumb deletion. Now working. --- django_lostplaces/lostplaces/models/models.py | 21 ++++++++++++++++++- django_lostplaces/lostplaces/models/place.py | 7 ++----- .../lostplaces/views/explorer_views.py | 3 +++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index 1f163ca..55c4844 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -11,7 +11,7 @@ import uuid from django.db import models 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.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): 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): """ Vouchers are authorization tokens to allow the registration of new users. diff --git a/django_lostplaces/lostplaces/models/place.py b/django_lostplaces/lostplaces/models/place.py index 8fc6790..a0d1b99 100644 --- a/django_lostplaces/lostplaces/models/place.py +++ b/django_lostplaces/lostplaces/models/place.py @@ -72,7 +72,7 @@ class PlaceAsset(Submittable): null=True ) -class PlaceImage (PlaceAsset): +class PlaceImage(PlaceAsset): """ PlaceImage defines an image file object that points to a file in uploads/. Intermediate image sizes are generated as defined in THUMBNAIL_ALIASES. @@ -104,7 +104,6 @@ class PlaceImage (PlaceAsset): return 'Image ' + str(self.pk) - # These two auto-delete files from filesystem when they are unneeded: @receiver(post_delete, sender=PlaceImage) @@ -118,7 +117,6 @@ def auto_delete_file_on_delete(sender, instance, **kwargs): thumbmanager = get_thumbnailer(instance.filename) thumbmanager.delete(save=False) - @receiver(pre_save, sender=PlaceImage) 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. new_file = instance.filename if not old_file == new_file: - if os.path.isfile(old_file.path): - os.remove(old_file.path) + old_file.delete(save=False) diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index 9d9ca3d..4330450 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -56,6 +56,7 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): return render(request, 'explorer/profile_update.html', context) def post(self, request, *args, **kwargs): + print(request.POST) explorer_user_change_form = ExplorerUserChangeForm( request.POST, instance=request.user @@ -70,6 +71,8 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): explorer_user_change_form.save() explorer_change_form.save() + print(explorer_change_form.cleaned_data) + messages.success( self.request, _('Successfully updated Explorer profile') From dac63e99ba455a5f390f5b41c94bdf1bb6ed55dc Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 16:00:29 +0100 Subject: [PATCH 35/36] Added Edit button to profile page. --- django_lostplaces/lostplaces/templates/explorer/profile.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html index 77db9a1..8bdd07d 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -71,6 +71,11 @@ {{asset_count}}
+ +
From c5f6355f193df939ebb1b158be6b4dc2ba425a60 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 25 Dec 2020 16:07:50 +0100 Subject: [PATCH 36/36] Updated translations (de). --- .../locale/de/LC_MESSAGES/django.po | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po b/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po index ca01b0c..1eaa7a9 100644 --- a/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po +++ b/django_lostplaces/lostplaces/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-12-25 01:22+0100\n" +"POT-Creation-Date: 2020-12-25 16:04+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Commander1024 \n" "Language-Team: LANGUAGE \n" @@ -74,19 +74,19 @@ msgstr "Adresse (URL)" msgid "link text" msgstr "Linktext" -#: models/models.py:46 -msgid "Biography / Description" +#: models/models.py:47 +msgid "Biography" msgstr "Beschreibung" -#: models/models.py:47 +#: models/models.py:48 msgid "Describe yourself, your preferences, etc. in a few sentences." msgstr "Beschreibe Dich selbst, Deine Vorlieben, usw. in ein paar Sätzen." -#: models/models.py:55 +#: models/models.py:56 msgid "Profile image" msgstr "Profilbild" -#: models/models.py:56 +#: models/models.py:57 msgid "Optional profile image for display in Explorer profile" msgstr "Optionales Profilbild zur Anzeige im Explorerprofil" @@ -144,19 +144,25 @@ msgstr "Alle Places" msgid "Place assets" msgstr "" -#: templates/explorer/profile.html:82 -msgid "Favorite places" -msgstr "Favoriten-Places" +#: templates/explorer/profile.html:76 +#, fuzzy +#| msgid "Edit Explorer profile" +msgid "Edit Profile" +msgstr "Explorerprofil bearbeiten" -#: templates/explorer/profile.html:98 +#: templates/explorer/profile.html:87 +msgid "Favorite places" +msgstr "Favoriten" + +#: templates/explorer/profile.html:103 msgid "Places submitted by" msgstr "Places hinzugefügt von" -#: templates/explorer/profile.html:113 +#: templates/explorer/profile.html:118 msgid "Images submitted by" msgstr "Bilder hinzugefügt von" -#: templates/explorer/profile.html:135 +#: templates/explorer/profile.html:140 msgid "Photo albums submitted by" msgstr "Fotoalben hinzugefügt von" @@ -176,7 +182,7 @@ msgstr "Ausloggen" #: templates/global.html:33 msgid "Profile" -msgstr "" +msgstr "Profil" #: templates/global.html:35 msgid "Admin" @@ -402,6 +408,16 @@ msgstr "Noch kein Konto?" msgid "Please login to proceed" msgstr "Bitte log Dich ein um fortzufahren" +#: views/explorer_views.py:78 +#, fuzzy +#| msgid "Successfully updated place" +msgid "Successfully updated Explorer profile" +msgstr "Place erfolgreich aktualisiert" + +#: views/explorer_views.py:84 views/place_views.py:105 +msgid "Please fill in all required fields." +msgstr "Bitte füll alle benötigten Felder aus." + #: views/place_image_views.py:26 msgid "Image(s) submitted successfully" msgstr "Bild(er) erfolgreich hinzugefügt" @@ -426,10 +442,6 @@ msgstr "Du darfst diesen Place nicht bearbeiten" msgid "Successfully created place" msgstr "Place erfolgreich erstellt" -#: views/place_views.py:105 -msgid "Please fill in all required fields." -msgstr "Bitte füll alle benötigten Felder aus." - #: views/place_views.py:112 msgid "Successfully deleted place" msgstr "Place erfolgreich gelöscht"