diff --git a/django_lostplaces/lostplaces/migrations/0004_auto_20201225_1702.py b/django_lostplaces/lostplaces/migrations/0004_gory_fix.py similarity index 100% rename from django_lostplaces/lostplaces/migrations/0004_auto_20201225_1702.py rename to django_lostplaces/lostplaces/migrations/0004_gory_fix.py diff --git a/django_lostplaces/lostplaces/migrations/0005_add_visited_places.py b/django_lostplaces/lostplaces/migrations/0005_add_visited_places.py new file mode 100644 index 0000000..3b4af82 --- /dev/null +++ b/django_lostplaces/lostplaces/migrations/0005_add_visited_places.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.4 on 2020-12-25 18:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces', '0004_auto_20201225_1702'), + ] + + operations = [ + migrations.AddField( + model_name='explorer', + name='visited_places', + field=models.ManyToManyField(blank=True, related_name='explorer_visits', to='lostplaces.Place', verbose_name='Explorers visited places'), + ), + ] diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index 2d39ca6..5914583 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -62,6 +62,12 @@ class Explorer(models.Model): verbose_name='Explorers favorite places', blank=True ) + visited_places = models.ManyToManyField( + Place, + related_name='explorer_visits', + verbose_name='Explorers visited places', + blank=True + ) def __str__(self): return self.user.username diff --git a/django_lostplaces/lostplaces/static/icons/favourite.svg b/django_lostplaces/lostplaces/static/icons/favorite.svg similarity index 100% rename from django_lostplaces/lostplaces/static/icons/favourite.svg rename to django_lostplaces/lostplaces/static/icons/favorite.svg diff --git a/django_lostplaces/lostplaces/static/icons/favourite_filled.svg b/django_lostplaces/lostplaces/static/icons/favorite_filled.svg similarity index 99% rename from django_lostplaces/lostplaces/static/icons/favourite_filled.svg rename to django_lostplaces/lostplaces/static/icons/favorite_filled.svg index c5cc50c..fdb73a4 100644 --- a/django_lostplaces/lostplaces/static/icons/favourite_filled.svg +++ b/django_lostplaces/lostplaces/static/icons/favorite_filled.svg @@ -13,7 +13,7 @@ viewBox="0 0 512.07 512.07" width="512" version="1.1" - sodipodi:docname="favourite_filled.svg" + sodipodi:docname="favorite_filled.svg" inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"> diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html index 24831e4..a2e49b9 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -90,9 +90,21 @@ {% endfor %} - {% include 'partials/nav/pagination.html' %} + + +
+
+

{% trans 'Visited places' %}

+
    + {% for place in explorer.visited_places.all %} +
  • + {% include 'partials/place_teaser.html' with place=place extended=True %} +
  • + {% endfor %} +
+ {% include 'partials/nav/pagination.html' %}
diff --git a/django_lostplaces/lostplaces/templates/partials/icons/place_favorite.html b/django_lostplaces/lostplaces/templates/partials/icons/place_favorite.html index d87ef9e..15f2881 100644 --- a/django_lostplaces/lostplaces/templates/partials/icons/place_favorite.html +++ b/django_lostplaces/lostplaces/templates/partials/icons/place_favorite.html @@ -4,11 +4,11 @@ {% 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/icons/place_visited.html b/django_lostplaces/lostplaces/templates/partials/icons/place_visited.html new file mode 100644 index 0000000..79232c2 --- /dev/null +++ b/django_lostplaces/lostplaces/templates/partials/icons/place_visited.html @@ -0,0 +1,14 @@ +{%load static %} +{% load i18n %} + +{% if request.user %} +{% if place in request.user.explorer.visited_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 aa1418f..7028eb1 100644 --- a/django_lostplaces/lostplaces/templates/partials/place_teaser.html +++ b/django_lostplaces/lostplaces/templates/partials/place_teaser.html @@ -31,7 +31,7 @@
diff --git a/django_lostplaces/lostplaces/templates/place/place_detail.html b/django_lostplaces/lostplaces/templates/place/place_detail.html index 5db1360..dbbd06f 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 }} {% include 'partials/icons/place_favorite.html' %}

+

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

{% if place.placeimages.first.filename.hero.url %}
diff --git a/django_lostplaces/lostplaces/urls.py b/django_lostplaces/lostplaces/urls.py index 29f5007..35f6ce4 100644 --- a/django_lostplaces/lostplaces/urls.py +++ b/django_lostplaces/lostplaces/urls.py @@ -4,6 +4,8 @@ from django.urls import path from lostplaces.views import ( HomeView, + FlatView, + OSMMapView, PlaceDetailView, PlaceListView, PlaceCreateView, @@ -13,37 +15,39 @@ from lostplaces.views import ( PlaceTagSubmitView, PlaceFavoriteView, PlaceUnfavoriteView, - PhotoAlbumCreateView, - PhotoAlbumDeleteView, + PlaceVisitCreateView, + PlaceVisitDeleteView, PlaceImageCreateView, PlaceImageDeleteView, - FlatView, + PhotoAlbumCreateView, + PhotoAlbumDeleteView, ExplorerProfileView, - ExplorerProfileUpdateView, - OSMMapView + ExplorerProfileUpdateView ) urlpatterns = [ path('', HomeView.as_view(), name='lostplaces_home'), - path('place//', PlaceDetailView.as_view(), name='place_detail'), - path('place/create/', PlaceCreateView.as_view(), name='place_create'), - path('photo_album/create/', PhotoAlbumCreateView.as_view(), name='photo_album_create'), - path('photo_album/delete/', PhotoAlbumDeleteView.as_view(), name='photo_album_delete'), - path('place/update//', PlaceUpdateView.as_view(), name='place_edit'), - path('place/delete//', PlaceDeleteView.as_view(), name='place_delete'), - path('place/', PlaceListView.as_view(), name='place_list'), - path('place_image/create/', PlaceImageCreateView.as_view(), name='place_image_create'), - path('place_image/delete/', PlaceImageDeleteView.as_view(), name='place_image_delete'), path('flat//', FlatView, name='flatpage'), + path('osm/', OSMMapView.as_view(), name='osm'), - # POST-only URLs for tag submission - 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/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'), - path('osm/', OSMMapView.as_view(), name='osm') + + path('place/', PlaceListView.as_view(), name='place_list'), + path('place//', PlaceDetailView.as_view(), name='place_detail'), + path('place/create/', PlaceCreateView.as_view(), name='place_create'), + path('place/update//', PlaceUpdateView.as_view(), name='place_edit'), + path('place/delete//', PlaceDeleteView.as_view(), name='place_delete'), + path('place/tag/create//', PlaceTagSubmitView.as_view(), name='place_tag_submit'), + path('place/tag/delete///', PlaceTagDeleteView.as_view(), name='place_tag_delete'), + path('place/fav/create//', PlaceFavoriteView.as_view(), name='place_favorite'), + path('place/fav/delete//', PlaceUnfavoriteView.as_view(), name='place_unfavorite'), + path('place/visit/create//', PlaceVisitCreateView.as_view(), name='place_visit_create'), + path('place/visit/delete//', PlaceVisitDeleteView.as_view(), name='place_visit_delete'), + + path('place_image/create//', PlaceImageCreateView.as_view(), name='place_image_create'), + path('place_image/delete//', PlaceImageDeleteView.as_view(), name='place_image_delete'), + + path('photo_album/create//', PhotoAlbumCreateView.as_view(), name='photo_album_create'), + path('photo_album/delete//', PhotoAlbumDeleteView.as_view(), name='photo_album_delete') ] diff --git a/django_lostplaces/lostplaces/views/place_views.py b/django_lostplaces/lostplaces/views/place_views.py index 379f02e..29069db 100644 --- a/django_lostplaces/lostplaces/views/place_views.py +++ b/django_lostplaces/lostplaces/views/place_views.py @@ -147,3 +147,23 @@ class PlaceUnfavoriteView(IsAuthenticatedMixin, View): request.user.explorer.save() return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk})) + +class PlaceVisitCreateView(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.visited_places.add(place) + request.user.explorer.save() + + return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk})) + +class PlaceVisitDeleteView(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.visited_places.remove(place) + request.user.explorer.save() + + return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk}))