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 diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index 16b53da..8c87ae1 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,13 @@ class Explorer(models.Model): related_name='explorer' ) + favorite_places = models.ManyToManyField( + Place, + related_name='favorite_places', + verbose_name='Explorers favorite places', + blank=True + ) + def __str__(self): return self.user.username 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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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}}

-
- -
+

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

+
+ +
-

{% 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/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 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 %}
-
- {% if place.placeimages.all|length > 0 %} + +
+ {% if place.placeimages.all|length > 0 %} - {% else %} + {% else %} - {% endif %} -
+ {% endif %} +
+
@@ -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_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 %}
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 @@ diff --git a/django_lostplaces/lostplaces/urls.py b/django_lostplaces/lostplaces/urls.py index 2796ed9..0e38282 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_unfavorite') + + ] diff --git a/django_lostplaces/lostplaces/views/place_views.py b/django_lostplaces/lostplaces/views/place_views.py index 137f706..c96726b 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