diff --git a/django_lostplaces/lostplaces/migrations/0002_remove_vouchers.py b/django_lostplaces/lostplaces/migrations/0002_remove_vouchers.py new file mode 100644 index 0000000..d87ac47 --- /dev/null +++ b/django_lostplaces/lostplaces/migrations/0002_remove_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/migrations/0003_voucher.py b/django_lostplaces/lostplaces/migrations/0003_voucher.py index b4be5d8..889f42a 100644 --- a/django_lostplaces/lostplaces/migrations/0003_voucher.py +++ b/django_lostplaces/lostplaces/migrations/0003_voucher.py @@ -6,7 +6,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('lostplaces', '0002_reomve_vouchers'), + ('lostplaces', '0002_remove_vouchers'), ] operations = [ diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index 5e9f910..d577405 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -16,6 +16,7 @@ from django.dispatch import receiver from django.utils.translation import ugettext_lazy as _ from lostplaces.models.abstract_models import Expireable +from lostplaces.models.place import Place from easy_thumbnails.fields import ThumbnailerImageField from easy_thumbnails.files import get_thumbnailer @@ -49,6 +50,13 @@ class Explorer(models.Model): help_text=_('Optional profile pic for display in explorer profile') ) + 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 aaf425b..0e49976 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -61,65 +61,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