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
|
|
|
|
from django.urls import reverse_lazy
|
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
|
|
|
|
from lostplaces_app.forms import ExplorerCreationForm
|
|
|
|
from lostplaces_app.models import Place, PhotoAlbum
|
2020-09-02 00:22:42 +02:00
|
|
|
from lostplaces_app.views import IsAuthenticated
|
2020-08-30 17:11:24 +02:00
|
|
|
|
2020-08-30 17:26:43 +02:00
|
|
|
from lostplaces_app.views.base_views import (
|
|
|
|
PlaceAssetCreateView,
|
|
|
|
PlaceAssetDeleteView
|
|
|
|
)
|
2020-08-30 17:11:24 +02:00
|
|
|
class SignUpView(SuccessMessageMixin, CreateView):
|
|
|
|
form_class = ExplorerCreationForm
|
|
|
|
success_url = reverse_lazy('login')
|
|
|
|
template_name = 'signup.html'
|
|
|
|
success_message = 'User created.'
|
|
|
|
|
2020-09-02 00:22:42 +02:00
|
|
|
class HomeView(IsAuthenticated, View):
|
2020-08-30 17:11:24 +02:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
place_list = Place.objects.all().order_by('-submitted_when')[:10]
|
|
|
|
place_map_center = Place.average_latlon(place_list)
|
|
|
|
context = {
|
|
|
|
'place_list': place_list,
|
|
|
|
'place_map_center': place_map_center
|
|
|
|
}
|
|
|
|
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'
|
|
|
|
success_message = 'Photo Album submitted'
|
|
|
|
|
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'
|
|
|
|
success_message = 'Photo Album deleted'
|
2020-09-03 00:11:08 +02:00
|
|
|
permission_denied_messsage = 'You do not have permissions to alter this photo album'
|
|
|
|
|
|
|
|
def CodexView(request):
|
2020-09-03 20:06:03 +02:00
|
|
|
return render(request, 'flat/codex.html')
|