1 # chloro - personal space
2 # Copyright (C) 2019 Frederic Peters
4 # This program is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Affero General Public License as published
6 # by the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from django.core.exceptions import PermissionDenied
18 from django.http import Http404
19 from django.views.generic import CreateView, DeleteView, DetailView, ListView, UpdateView, TemplateView
21 from .models import Note
24 class NoteView(DetailView):
27 def get(self, request, *args, **kwargs):
28 note = self.get_object()
29 if kwargs.get('year'):
30 # check date does match
31 creation = self.get_object().creation_timestamp
32 if (creation.year, creation.month, creation.day) != (
38 if not note.published and not request.user.is_staff:
39 raise PermissionDenied()
40 return super(NoteView, self).get(request, *args, **kwargs)
43 class NoteEditView(UpdateView):
45 fields = ['title', 'slug', 'text', 'tags', 'published']
48 class NoteAddView(CreateView):
50 fields = ['title', 'slug', 'text', 'tags', 'published']
53 class NoteDeleteView(DeleteView):
56 def get_success_url(self):
60 class HomeView(TemplateView):
61 template_name = 'phyll/home.html'
64 class ListOnTagView(ListView):
67 def get_queryset(self):
68 qs = Note.objects.filter(tags__name__in=[self.kwargs['tag']])
69 if not self.request.user.is_staff:
70 qs = qs.filter(published=True)