Compare commits

...

11 Commits

13 changed files with 102 additions and 32 deletions

View File

@ -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_gory_fix'),
]
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'),
),
]

View File

@ -62,6 +62,12 @@ class Explorer(models.Model):
verbose_name='Explorers favorite places', verbose_name='Explorers favorite places',
blank=True blank=True
) )
visited_places = models.ManyToManyField(
Place,
related_name='explorer_visits',
verbose_name='Explorers visited places',
blank=True
)
def __str__(self): def __str__(self):
return self.user.username return self.user.username
@ -89,7 +95,6 @@ def auto_delete_file_on_change(sender, instance, **kwargs):
old_file = Explorer.objects.get(pk=instance.pk).profile_image old_file = Explorer.objects.get(pk=instance.pk).profile_image
except Explorer.DoesNotExist: except Explorer.DoesNotExist:
return False return False
print("Deleting:", old_file)
new_file = instance.profile_image new_file = instance.profile_image
if not old_file == new_file: if not old_file == new_file:
old_file.delete(save=False) old_file.delete(save=False)

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -13,7 +13,7 @@
viewBox="0 0 512.07 512.07" viewBox="0 0 512.07 512.07"
width="512" width="512"
version="1.1" version="1.1"
sodipodi:docname="favourite_filled.svg" sodipodi:docname="favorite_filled.svg"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"> inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)">
<metadata <metadata
id="metadata11"> id="metadata11">

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 108 KiB

View File

@ -90,9 +90,21 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% include 'partials/nav/pagination.html' %} {% include 'partials/nav/pagination.html' %}
</div>
</section>
<section class="LP-Section">
<div class="LP-PlaceList">
<h1 class="LP-Headline">{% trans 'Visited places' %}</h1>
<ul class="LP-PlaceList__List">
{% for place in explorer.visited_places.all %}
<li class="LP-PlaceList__Item">
{% include 'partials/place_teaser.html' with place=place extended=True %}
</li>
{% endfor %}
</ul>
{% include 'partials/nav/pagination.html' %}
</div> </div>
</section> </section>

View File

@ -4,11 +4,11 @@
{% if request.user %} {% if request.user %}
{% if place in request.user.explorer.favorite_places.all %} {% if place in request.user.explorer.favorite_places.all %}
<a href="{% url 'place_unfavorite' place_id=place.id %}" class="LP-Link" title="{% trans 'Remove from favorites' %}"> <a href="{% url 'place_unfavorite' place_id=place.id %}" class="LP-Link" title="{% trans 'Remove from favorites' %}">
<img class="LP-Icon" src="{% static '/icons/favourite_filled.svg' %}" /> <img class="LP-Icon" src="{% static '/icons/favorite_filled.svg' %}" />
</a> </a>
{%else%} {%else%}
<a href="{% url 'place_favorite' place_id=place.id %}" class="LP-Link" title="{% trans 'Save as favorite' %}"> <a href="{% url 'place_favorite' place_id=place.id %}" class="LP-Link" title="{% trans 'Save as favorite' %}">
<img class="LP-Icon" src="{% static '/icons/favourite.svg' %}" /> <img class="LP-Icon" src="{% static '/icons/favorite.svg' %}" />
</a> </a>
{% endif %} {% endif %}
{% endif %} {% endif %}

View File

@ -0,0 +1,14 @@
{%load static %}
{% load i18n %}
{% if request.user %}
{% if place in request.user.explorer.visited_places.all %}
<a href="{% url 'place_visit_delete' place_id=place.id %}" class="LP-Link" title="{% trans 'Remove from visits' %}">
<img class="LP-Icon" src="{% static '/icons/pin_filled.svg' %}" />
</a>
{%else%}
<a href="{% url 'place_visit_create' place_id=place.id %}" class="LP-Link" title="{% trans 'Save as visited' %}">
<img class="LP-Icon" src="{% static '/icons/pin.svg' %}" />
</a>
{% endif %}
{% endif %}

View File

@ -31,7 +31,7 @@
<div class="LP-PlaceTeaser__Icons"> <div class="LP-PlaceTeaser__Icons">
<ul class="LP-Icon__List"> <ul class="LP-Icon__List">
<li class="LP-Icon__Item">{% include 'partials/icons/place_favorite.html' with place=place%}</li> <li class="LP-Icon__Item">{% include 'partials/icons/place_favorite.html' with place=place%}</li>
<li class="LP-Icon__Item"><img class="LP-Icon" src="{% static '/icons/pin.svg' %}" /></li> <li class="LP-Icon__Item">{% include 'partials/icons/place_visited.html' with place=place%}</li>
<li class="LP-Icon__Item"><img class="LP-Icon" src="{% static '/icons/flag.svg' %}" /></li> <li class="LP-Icon__Item"><img class="LP-Icon" src="{% static '/icons/flag.svg' %}" /></li>
</ul> </ul>
</div> </div>

View File

@ -23,7 +23,7 @@
<article class="LP-PlaceDetail"> <article class="LP-PlaceDetail">
<header class="LP-PlaceDetail__Header"> <header class="LP-PlaceDetail__Header">
<h1 class="LP-Headline">{{ place.name }} {% include 'partials/icons/place_favorite.html' %}</h1> <h1 class="LP-Headline">{{ place.name }} {% include 'partials/icons/place_favorite.html' %} {% include 'partials/icons/place_visited.html' %}</h1>
{% if place.placeimages.first.filename.hero.url %} {% if place.placeimages.first.filename.hero.url %}
<figure class="LP-PlaceDetail__Image"> <figure class="LP-PlaceDetail__Image">
<img src="{{ place.placeimages.first.filename.hero.url }}" class="LP-Image" /> <img src="{{ place.placeimages.first.filename.hero.url }}" class="LP-Image" />

View File

@ -4,6 +4,8 @@
from django.urls import path from django.urls import path
from lostplaces.views import ( from lostplaces.views import (
HomeView, HomeView,
FlatView,
OSMMapView,
PlaceDetailView, PlaceDetailView,
PlaceListView, PlaceListView,
PlaceCreateView, PlaceCreateView,
@ -13,37 +15,39 @@ from lostplaces.views import (
PlaceTagSubmitView, PlaceTagSubmitView,
PlaceFavoriteView, PlaceFavoriteView,
PlaceUnfavoriteView, PlaceUnfavoriteView,
PhotoAlbumCreateView, PlaceVisitCreateView,
PhotoAlbumDeleteView, PlaceVisitDeleteView,
PlaceImageCreateView, PlaceImageCreateView,
PlaceImageDeleteView, PlaceImageDeleteView,
FlatView, PhotoAlbumCreateView,
PhotoAlbumDeleteView,
ExplorerProfileView, ExplorerProfileView,
ExplorerProfileUpdateView, ExplorerProfileUpdateView
OSMMapView
) )
urlpatterns = [ urlpatterns = [
path('', HomeView.as_view(), name='lostplaces_home'), path('', HomeView.as_view(), name='lostplaces_home'),
path('place/<int:pk>/', PlaceDetailView.as_view(), name='place_detail'),
path('place/create/', PlaceCreateView.as_view(), name='place_create'),
path('photo_album/create/<int:place_id>', PhotoAlbumCreateView.as_view(), name='photo_album_create'),
path('photo_album/delete/<int:pk>', PhotoAlbumDeleteView.as_view(), name='photo_album_delete'),
path('place/update/<int:pk>/', PlaceUpdateView.as_view(), name='place_edit'),
path('place/delete/<int:pk>/', PlaceDeleteView.as_view(), name='place_delete'),
path('place/', PlaceListView.as_view(), name='place_list'),
path('place_image/create/<int:place_id>', PlaceImageCreateView.as_view(), name='place_image_create'),
path('place_image/delete/<int:pk>', PlaceImageDeleteView.as_view(), name='place_image_delete'),
path('flat/<slug:slug>/', FlatView, name='flatpage'), path('flat/<slug:slug>/', FlatView, name='flatpage'),
path('osm/', OSMMapView.as_view(), name='osm'),
# POST-only URLs for tag submission
path('place/tag/<int:tagged_id>', PlaceTagSubmitView.as_view(), name='place_tag_submit'),
path('place/tag/delete/<int:tagged_id>/<int:tag_id>', PlaceTagDeleteView.as_view(), name='place_tag_delete'),
path('explorer/<int:explorer_id>/', ExplorerProfileView.as_view(), name='explorer_profile'), path('explorer/<int:explorer_id>/', ExplorerProfileView.as_view(), name='explorer_profile'),
path('explorer/update/', ExplorerProfileUpdateView.as_view(), name='explorer_profile_update'), path('explorer/update/', ExplorerProfileUpdateView.as_view(), name='explorer_profile_update'),
path('explorer/favorite/<int:place_id>/', PlaceFavoriteView.as_view(), name='place_favorite'), path('place/', PlaceListView.as_view(), name='place_list'),
path('explorer/unfavorite/<int:place_id>/', PlaceUnfavoriteView.as_view(), name='place_unfavorite'), path('place/<int:pk>/', PlaceDetailView.as_view(), name='place_detail'),
path('osm/', OSMMapView.as_view(), name='osm') path('place/create/', PlaceCreateView.as_view(), name='place_create'),
path('place/update/<int:pk>/', PlaceUpdateView.as_view(), name='place_edit'),
path('place/delete/<int:pk>/', PlaceDeleteView.as_view(), name='place_delete'),
path('place/tag/create/<int:tagged_id>/', PlaceTagSubmitView.as_view(), name='place_tag_submit'),
path('place/tag/delete/<int:tagged_id>/<int:tag_id>/', PlaceTagDeleteView.as_view(), name='place_tag_delete'),
path('place/fav/create/<int:place_id>/', PlaceFavoriteView.as_view(), name='place_favorite'),
path('place/fav/delete/<int:place_id>/', PlaceUnfavoriteView.as_view(), name='place_unfavorite'),
path('place/visit/create/<int:place_id>/', PlaceVisitCreateView.as_view(), name='place_visit_create'),
path('place/visit/delete/<int:place_id>/', PlaceVisitDeleteView.as_view(), name='place_visit_delete'),
path('place_image/create/<int:place_id>/', PlaceImageCreateView.as_view(), name='place_image_create'),
path('place_image/delete/<int:pk>/', PlaceImageDeleteView.as_view(), name='place_image_delete'),
path('photo_album/create/<int:place_id>/', PhotoAlbumCreateView.as_view(), name='photo_album_create'),
path('photo_album/delete/<int:pk>/', PhotoAlbumDeleteView.as_view(), name='photo_album_delete')
] ]

View File

@ -56,7 +56,6 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View):
return render(request, 'explorer/profile_update.html', context) return render(request, 'explorer/profile_update.html', context)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
print(request.POST)
explorer_user_change_form = ExplorerUserChangeForm( explorer_user_change_form = ExplorerUserChangeForm(
request.POST, request.POST,
instance=request.user instance=request.user
@ -71,8 +70,6 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View):
explorer_user_change_form.save() explorer_user_change_form.save()
explorer_change_form.save() explorer_change_form.save()
print(explorer_change_form.cleaned_data)
messages.success( messages.success(
self.request, self.request,
_('Successfully updated Explorer profile') _('Successfully updated Explorer profile')

View File

@ -147,3 +147,23 @@ class PlaceUnfavoriteView(IsAuthenticatedMixin, View):
request.user.explorer.save() request.user.explorer.save()
return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk})) 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}))