2020-09-19 22:50:07 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2020-08-30 17:11:24 +02:00
|
|
|
from django.views import View
|
|
|
|
from django.views.generic.edit import CreateView
|
|
|
|
|
|
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
|
|
|
from django.contrib import messages
|
2020-12-25 13:00:30 +01:00
|
|
|
from django.urls import reverse_lazy, reverse
|
2020-09-07 22:16:09 +02:00
|
|
|
from django.shortcuts import render, redirect, get_object_or_404
|
2020-09-02 00:08:00 +02:00
|
|
|
from django.http import HttpResponseForbidden
|
2020-10-11 07:50:15 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2020-08-30 17:11:24 +02:00
|
|
|
|
2020-12-24 20:25:05 +01:00
|
|
|
from lostplaces.forms import SignupVoucherForm, TagSubmitForm
|
2021-10-02 03:44:15 +02:00
|
|
|
from lostplaces.models import Place, PhotoAlbum, ExternalLink
|
2020-09-14 17:26:17 +02:00
|
|
|
from lostplaces.views.base_views import IsAuthenticatedMixin
|
2020-12-25 12:57:05 +01:00
|
|
|
from lostplaces.common import redirect_referer_or
|
2020-08-30 17:11:24 +02:00
|
|
|
|
2020-09-14 17:26:17 +02:00
|
|
|
from lostplaces.views.base_views import (
|
2020-08-30 17:26:43 +02:00
|
|
|
PlaceAssetCreateView,
|
2020-09-02 00:08:00 +02:00
|
|
|
PlaceAssetDeleteView,
|
2020-08-30 17:26:43 +02:00
|
|
|
)
|
2020-09-02 00:08:00 +02:00
|
|
|
|
|
|
|
from taggit.models import Tag
|
|
|
|
|
2020-08-30 17:11:24 +02:00
|
|
|
class SignUpView(SuccessMessageMixin, CreateView):
|
2020-12-24 20:25:05 +01:00
|
|
|
form_class = SignupVoucherForm
|
2020-08-30 17:11:24 +02:00
|
|
|
success_url = reverse_lazy('login')
|
|
|
|
template_name = 'signup.html'
|
2020-10-11 07:50:15 +02:00
|
|
|
success_message = _('User created')
|
2020-08-30 17:11:24 +02:00
|
|
|
|
2020-09-13 10:56:18 +02:00
|
|
|
class HomeView(IsAuthenticatedMixin, View):
|
2020-08-30 17:11:24 +02:00
|
|
|
def get(self, request, *args, **kwargs):
|
2021-10-01 22:38:44 +02:00
|
|
|
place_list = request.user.explorer.get_places_eligible_to_see()
|
2020-08-30 17:11:24 +02:00
|
|
|
context = {
|
2020-09-17 22:02:37 +02:00
|
|
|
'place_list': place_list,
|
2020-09-13 20:15:49 +02:00
|
|
|
'mapping_config': {
|
2020-09-17 22:02:37 +02:00
|
|
|
'all_points': place_list,
|
2020-09-12 11:47:42 +02:00
|
|
|
'map_center': Place.average_latlon(place_list)
|
|
|
|
}
|
2020-08-30 17:11:24 +02:00
|
|
|
}
|
|
|
|
return render(request, 'home.html', context)
|
|
|
|
|
2020-09-02 00:22:42 +02:00
|
|
|
def handle_no_permission(self):
|
2020-09-02 00:26:03 +02:00
|
|
|
place_list = Place.objects.all().order_by('-submitted_when')[:5]
|
2020-09-02 00:22:42 +02:00
|
|
|
context = {
|
|
|
|
'place_list': place_list
|
|
|
|
}
|
|
|
|
return render(self.request, 'home_unauth.html', context)
|
|
|
|
|
2020-08-30 17:26:43 +02:00
|
|
|
class PhotoAlbumCreateView(PlaceAssetCreateView):
|
2020-08-30 17:11:24 +02:00
|
|
|
model = PhotoAlbum
|
|
|
|
fields = ['url', 'label']
|
|
|
|
template_name = 'photo_album/photo_album_create.html'
|
2020-10-11 21:27:27 +02:00
|
|
|
success_message = _('Photo album link submitted')
|
2020-08-30 17:11:24 +02:00
|
|
|
|
2020-08-30 17:26:43 +02:00
|
|
|
class PhotoAlbumDeleteView(PlaceAssetDeleteView):
|
2020-08-30 17:11:24 +02:00
|
|
|
model = PhotoAlbum
|
|
|
|
pk_url_kwarg = 'pk'
|
2020-10-11 21:27:27 +02:00
|
|
|
success_message = _('Photo album link deleted')
|
|
|
|
permission_denied_messsage = _('You are not allowed to edit this photo album link')
|
2020-09-03 00:11:08 +02:00
|
|
|
|
2021-10-02 03:44:15 +02:00
|
|
|
class ExternalLinkCreateView(PlaceAssetCreateView):
|
|
|
|
model = ExternalLink
|
|
|
|
fields = ['url', 'label', 'linktype']
|
|
|
|
template_name = 'external_link/external_link_create.html'
|
|
|
|
success_message = _('External link submitted')
|
|
|
|
|
|
|
|
class ExternalLinkDeleteView(PlaceAssetDeleteView):
|
|
|
|
model = ExternalLink
|
|
|
|
pk_url_kwarg = 'pk'
|
|
|
|
success_message = _('External link deleted')
|
|
|
|
permission_denied_messsage = _('You are not allowed to edit this external link')
|
|
|
|
|
2020-09-13 10:56:18 +02:00
|
|
|
class PlaceTagSubmitView(IsAuthenticatedMixin, View):
|
2020-09-12 11:24:16 +02:00
|
|
|
def post(self, request, tagged_id, *args, **kwargs):
|
2020-09-18 23:32:52 +02:00
|
|
|
place = get_object_or_404(Place, pk=tagged_id)
|
2020-08-30 18:39:45 +02:00
|
|
|
form = TagSubmitForm(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
tag_list_raw = form.cleaned_data['tag_list']
|
|
|
|
tag_list_raw = tag_list_raw.strip().split(',')
|
|
|
|
tag_list = []
|
|
|
|
for tag in tag_list_raw:
|
|
|
|
tag_list.append(tag.strip())
|
|
|
|
place.tags.add(*tag_list)
|
|
|
|
place.save()
|
|
|
|
|
|
|
|
return redirect(reverse_lazy('place_detail', kwargs={'pk': place.id}))
|
2020-09-02 00:08:00 +02:00
|
|
|
|
2020-09-13 10:56:18 +02:00
|
|
|
class PlaceTagDeleteView(IsAuthenticatedMixin, View):
|
2020-09-02 00:08:00 +02:00
|
|
|
def get(self, request, tagged_id, tag_id, *args, **kwargs):
|
2020-09-18 23:32:52 +02:00
|
|
|
place = get_object_or_404(Place, pk=tagged_id)
|
|
|
|
tag = get_object_or_404(Tag, pk=tag_id)
|
2020-09-02 00:08:00 +02:00
|
|
|
place.tags.remove(tag)
|
2020-12-25 12:57:05 +01:00
|
|
|
|
|
|
|
return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': tagged_id}))
|
|
|
|
|
2020-09-07 22:16:09 +02:00
|
|
|
def FlatView(request, slug):
|
2020-10-11 06:15:40 +02:00
|
|
|
if request.LANGUAGE_CODE == 'de':
|
|
|
|
return render(request, 'flat/' + slug + '-de' + '.html')
|
|
|
|
else:
|
|
|
|
return render(request, 'flat/' + slug + '.html')
|
2020-12-25 13:29:34 +01:00
|
|
|
|
|
|
|
class OSMMapView(IsAuthenticatedMixin, View):
|
|
|
|
def get(self, request):
|
|
|
|
place_list = Place.objects.all()
|
|
|
|
context = {
|
|
|
|
'mapping_config': {
|
|
|
|
'all_points': place_list,
|
|
|
|
'map_center': Place.average_latlon(place_list)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return render(request, 'osm_map_full.html', context)
|