From abca9468837f6e170ab643923cfb657c5c1403d4 Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 24 Dec 2020 14:48:11 +0100 Subject: [PATCH 01/11] Model for favorite system --- django_lostplaces/lostplaces/models/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index 16b53da..a15a7e6 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -14,6 +14,7 @@ from django.db.models.signals import post_save from django.dispatch import receiver from lostplaces.models.abstract_models import Expireable +from lostplaces.models.place import Place class Explorer(models.Model): """ @@ -27,6 +28,8 @@ class Explorer(models.Model): related_name='explorer' ) + favorite_places = models.ManyToManyField(Place, related_name='favorite_places', verbose_name='Explorers favorite places') + def __str__(self): return self.user.username From dbbd7b0802acefab209115ce46b40f4e9491cd36 Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 24 Dec 2020 15:55:37 +0100 Subject: [PATCH 02/11] rename migrationfile --- .../migrations/0002_remove_vouchers.py | 22 ------------------- .../migrations/0002_reomve_vouchers.py | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 22 deletions(-) delete mode 100644 django_lostplaces/lostplaces/migrations/0002_remove_vouchers.py create mode 100644 django_lostplaces/lostplaces/migrations/0002_reomve_vouchers.py diff --git a/django_lostplaces/lostplaces/migrations/0002_remove_vouchers.py b/django_lostplaces/lostplaces/migrations/0002_remove_vouchers.py deleted file mode 100644 index d3727d9..0000000 --- a/django_lostplaces/lostplaces/migrations/0002_remove_vouchers.py +++ /dev/null @@ -1,22 +0,0 @@ - # Generated by Django 3.1.1 on 2020-10-04 19:37 - # Edited by reverend - - import datetime - from django.db import migrations, models - import django.utils.timezone - from django.utils.timezone import utc - - class Migration(migrations.Migration): - - dependencies = [ - ('lostplaces', '0001_initial'), - ] - - operations = [ - migrations.DeleteModel( - name='Voucher' - ), - migrations.DeleteModel( - name='Expireable' - ) - ] \ No newline at end of file diff --git a/django_lostplaces/lostplaces/migrations/0002_reomve_vouchers.py b/django_lostplaces/lostplaces/migrations/0002_reomve_vouchers.py new file mode 100644 index 0000000..d87ac47 --- /dev/null +++ b/django_lostplaces/lostplaces/migrations/0002_reomve_vouchers.py @@ -0,0 +1,22 @@ +# Generated by Django 3.1.1 on 2020-10-04 19:37 +# Edited by reverend + +import datetime +from django.db import migrations, models +import django.utils.timezone +from django.utils.timezone import utc + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces', '0001_initial'), + ] + + operations = [ + migrations.DeleteModel( + name='Voucher' + ), + migrations.DeleteModel( + name='Expireable' + ) + ] \ No newline at end of file From f9744699964d287c4ea33a29b6ae6464da7c7ef1 Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 24 Dec 2020 15:56:02 +0100 Subject: [PATCH 03/11] formatting --- django_lostplaces/lostplaces/models/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index a15a7e6..49c1000 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -28,7 +28,11 @@ class Explorer(models.Model): related_name='explorer' ) - favorite_places = models.ManyToManyField(Place, related_name='favorite_places', verbose_name='Explorers favorite places') + favorite_places = models.ManyToManyField( + Place, + related_name='favorite_places', + verbose_name='Explorers favorite places' + ) def __str__(self): return self.user.username From 8f048369bfe2031859ad7e6616fee70264e84bcf Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 24 Dec 2020 15:56:33 +0100 Subject: [PATCH 04/11] Favorite/Unfavorite Views --- django_lostplaces/lostplaces/urls.py | 9 +++++- .../lostplaces/views/place_views.py | 32 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/urls.py b/django_lostplaces/lostplaces/urls.py index 2796ed9..80138ce 100644 --- a/django_lostplaces/lostplaces/urls.py +++ b/django_lostplaces/lostplaces/urls.py @@ -11,6 +11,8 @@ from lostplaces.views import ( PlaceDeleteView, PlaceTagDeleteView, PlaceTagSubmitView, + PlaceFavoriteView, + PlaceUnfavoriteView, PhotoAlbumCreateView, PhotoAlbumDeleteView, PlaceImageCreateView, @@ -36,5 +38,10 @@ urlpatterns = [ path('place/tag/', PlaceTagSubmitView.as_view(), name='place_tag_submit'), path('place/tag/delete//', PlaceTagDeleteView.as_view(), name='place_tag_delete'), - path('explorer//', ExplorerProfileView.as_view(), name='explorer_profile') + path('explorer//', ExplorerProfileView.as_view(), name='explorer_profile'), + + path('explorer/favorite//', PlaceFavoriteView.as_view(), name='place_favorite'), + path('explorer/unfavorite//', PlaceUnfavoriteView.as_view(), name='place_favorite') + + ] diff --git a/django_lostplaces/lostplaces/views/place_views.py b/django_lostplaces/lostplaces/views/place_views.py index 137f706..ea078bf 100644 --- a/django_lostplaces/lostplaces/views/place_views.py +++ b/django_lostplaces/lostplaces/views/place_views.py @@ -119,3 +119,35 @@ class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, DeleteView): def get_place(self): return self.get_object() + +class PlaceFavoriteView(IsAuthenticatedMixin, View): + + def get(self, request, place_id): + place = get_object_or_404(Place, id=place_id) + if request.user is not None: + request.user.explorer.favorite_places.add(place) + request.user.explorer.save() + + referer = request.META.get('HTTP_referer') + if referer is not None: + return redirect(referer) + else: + return redirect( + reverse_lazy('place_detail', kwargs={'pk': place.pk}) + ) + +class PlaceUnfavoriteView(IsAuthenticatedMixin, View): + + def get(self, request, place_id): + place = get_object_or_404(Place, id=place_id) + if request.user is not None: + request.user.explorer.favorite_places.remove(place) + request.user.explorer.save() + + referer = request.META.get('HTTP_referer') + if referer is not None: + return redirect(referer) + else: + return redirect( + reverse_lazy('place_detail', kwargs={'pk': place.pk}) + ) \ No newline at end of file From b31dc9fc5f2388a7f4a382a056b90e3ef3918bb7 Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 24 Dec 2020 16:41:30 +0100 Subject: [PATCH 05/11] Url name changed --- django_lostplaces/lostplaces/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/urls.py b/django_lostplaces/lostplaces/urls.py index 80138ce..0e38282 100644 --- a/django_lostplaces/lostplaces/urls.py +++ b/django_lostplaces/lostplaces/urls.py @@ -41,7 +41,7 @@ urlpatterns = [ path('explorer//', ExplorerProfileView.as_view(), name='explorer_profile'), path('explorer/favorite//', PlaceFavoriteView.as_view(), name='place_favorite'), - path('explorer/unfavorite//', PlaceUnfavoriteView.as_view(), name='place_favorite') + path('explorer/unfavorite//', PlaceUnfavoriteView.as_view(), name='place_unfavorite') ] From 916c4b80f7900567860bcbecc214eb325cc0d7b9 Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 24 Dec 2020 16:42:27 +0100 Subject: [PATCH 06/11] Filed not required in django admin --- 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 49c1000..8c87ae1 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -31,7 +31,8 @@ class Explorer(models.Model): favorite_places = models.ManyToManyField( Place, related_name='favorite_places', - verbose_name='Explorers favorite places' + verbose_name='Explorers favorite places', + blank=True ) def __str__(self): From 86f95a5dd0f8a04f4a22311f5f2664052496e338 Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 24 Dec 2020 16:42:34 +0100 Subject: [PATCH 07/11] New icon --- .../static/icons/favourite_filled.svg | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 django_lostplaces/lostplaces/static/icons/favourite_filled.svg diff --git a/django_lostplaces/lostplaces/static/icons/favourite_filled.svg b/django_lostplaces/lostplaces/static/icons/favourite_filled.svg new file mode 100644 index 0000000..c5cc50c --- /dev/null +++ b/django_lostplaces/lostplaces/static/icons/favourite_filled.svg @@ -0,0 +1,163 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From c7b699f61594209bca197696f85e34044ad1204b Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 24 Dec 2020 16:43:01 +0100 Subject: [PATCH 08/11] Changed link location in place teaser --- .../templates/explorer/profile.html | 100 +++++++++--------- .../lostplaces/templates/home.html | 4 +- .../templates/partials/place_teaser.html | 18 ++-- .../templates/place/place_list.html | 4 +- 4 files changed, 61 insertions(+), 65 deletions(-) diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html index 4cf7948..cf4cd63 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -45,65 +45,63 @@
-
-

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

- +
+

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

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

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

-
-
    - {% for place_image in assets.placeimages.all %} -
  • - - - - {% if user.explorer == place_image.submitted_by%} - - - - - - {% endif %} -
  • - {% endfor %} -
-
+

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

+
+
    + {% for place_image in assets.placeimages.all %} +
  • + + + + {% if user.explorer == place_image.submitted_by%} + + + + + + {% endif %} +
  • + {% endfor %} +
+
-

{% trans 'Photo albums submitted by' %} {{explorer.user.username}}

- +

{% trans 'Photo albums submitted by' %} {{explorer.user.username}}

+
{% endblock maincontent %} \ No newline at end of file diff --git a/django_lostplaces/lostplaces/templates/home.html b/django_lostplaces/lostplaces/templates/home.html index 1694e93..db7168b 100644 --- a/django_lostplaces/lostplaces/templates/home.html +++ b/django_lostplaces/lostplaces/templates/home.html @@ -21,9 +21,7 @@ diff --git a/django_lostplaces/lostplaces/templates/partials/place_teaser.html b/django_lostplaces/lostplaces/templates/partials/place_teaser.html index 15929a5..35e5242 100644 --- a/django_lostplaces/lostplaces/templates/partials/place_teaser.html +++ b/django_lostplaces/lostplaces/templates/partials/place_teaser.html @@ -1,13 +1,15 @@ {%load static %}
- +
@@ -20,15 +22,15 @@

{% if place.description|length > 210 %} - {{place.description|truncatechars:210|truncatewords:-1}} + {{place.description|truncatechars:210|truncatewords:-1}} {% else %} - {{place.description}} + {{place.description}} {% endif %}

    -
  • +
  • {% include 'partials/icons/place_favorite.html' with place=place%}
diff --git a/django_lostplaces/lostplaces/templates/place/place_list.html b/django_lostplaces/lostplaces/templates/place/place_list.html index 058bee1..c23f451 100644 --- a/django_lostplaces/lostplaces/templates/place/place_list.html +++ b/django_lostplaces/lostplaces/templates/place/place_list.html @@ -17,9 +17,7 @@ From d547ee9db319113c869a10989a23153aab8fabe3 Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 24 Dec 2020 16:43:14 +0100 Subject: [PATCH 09/11] favorite partial --- .../templates/partials/icons/place_favorite.html | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 django_lostplaces/lostplaces/templates/partials/icons/place_favorite.html diff --git a/django_lostplaces/lostplaces/templates/partials/icons/place_favorite.html b/django_lostplaces/lostplaces/templates/partials/icons/place_favorite.html new file mode 100644 index 0000000..d87ef9e --- /dev/null +++ b/django_lostplaces/lostplaces/templates/partials/icons/place_favorite.html @@ -0,0 +1,14 @@ +{%load static %} +{% load i18n %} + +{% if request.user %} +{% if place in request.user.explorer.favorite_places.all %} + + + +{%else%} + + + +{% endif %} +{% endif %} \ No newline at end of file From 61cf14841702e8b1c8ac85ffc619435a6afc2159 Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 24 Dec 2020 16:43:33 +0100 Subject: [PATCH 10/11] Displaying favorite icon on detail page --- django_lostplaces/lostplaces/templates/place/place_detail.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/templates/place/place_detail.html b/django_lostplaces/lostplaces/templates/place/place_detail.html index 6d91170..7ddbda1 100644 --- a/django_lostplaces/lostplaces/templates/place/place_detail.html +++ b/django_lostplaces/lostplaces/templates/place/place_detail.html @@ -23,7 +23,7 @@
-

{{ place.name }}

+

{{ place.name }} {% include 'partials/icons/place_favorite.html' %}

{% if place.placeimages.first.filename.hero.url %}
From 4a43a4bf3764b2d59a2c10369a3b248148436a73 Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 24 Dec 2020 16:43:43 +0100 Subject: [PATCH 11/11] typo --- django_lostplaces/lostplaces/views/place_views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_lostplaces/lostplaces/views/place_views.py b/django_lostplaces/lostplaces/views/place_views.py index ea078bf..c96726b 100644 --- a/django_lostplaces/lostplaces/views/place_views.py +++ b/django_lostplaces/lostplaces/views/place_views.py @@ -128,7 +128,7 @@ class PlaceFavoriteView(IsAuthenticatedMixin, View): request.user.explorer.favorite_places.add(place) request.user.explorer.save() - referer = request.META.get('HTTP_referer') + referer = request.META.get('HTTP_REFERER') if referer is not None: return redirect(referer) else: @@ -144,7 +144,7 @@ class PlaceUnfavoriteView(IsAuthenticatedMixin, View): request.user.explorer.favorite_places.remove(place) request.user.explorer.save() - referer = request.META.get('HTTP_referer') + referer = request.META.get('HTTP_REFERER') if referer is not None: return redirect(referer) else: