From 34d500560508bd019e0fb28c5e45cd731dbb7569 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 29 Dec 2019 19:42:24 +0100 Subject: [PATCH] misc: extend notes with a "published" flag --- .../phyll/migrations/0003_note_published.py | 20 +++++++++++++++++++ chloro/phyll/models.py | 1 + chloro/phyll/static/css/style.scss | 3 +++ chloro/phyll/templates/phyll/note_list.html | 2 +- chloro/phyll/views.py | 14 +++++++++---- 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 chloro/phyll/migrations/0003_note_published.py diff --git a/chloro/phyll/migrations/0003_note_published.py b/chloro/phyll/migrations/0003_note_published.py new file mode 100644 index 0000000..7c5f05e --- /dev/null +++ b/chloro/phyll/migrations/0003_note_published.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.17 on 2019-12-29 18:39 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('phyll', '0002_auto_20191229_1932'), + ] + + operations = [ + migrations.AddField( + model_name='note', + name='published', + field=models.BooleanField(default=True, verbose_name='Published'), + ), + ] diff --git a/chloro/phyll/models.py b/chloro/phyll/models.py index 2307389..1f9914b 100644 --- a/chloro/phyll/models.py +++ b/chloro/phyll/models.py @@ -26,6 +26,7 @@ class Note(models.Model): slug = models.SlugField(_('Slug'), max_length=150) text = RichTextField(_('Text'), blank=True, null=True) tags = TaggableManager(_('Tags'), blank=True) + published = models.BooleanField(_('Published'), default=True) creation_timestamp = models.DateTimeField(auto_now_add=True) last_update_timestamp = models.DateTimeField(auto_now=True) diff --git a/chloro/phyll/static/css/style.scss b/chloro/phyll/static/css/style.scss index e25a946..3c78e42 100644 --- a/chloro/phyll/static/css/style.scss +++ b/chloro/phyll/static/css/style.scss @@ -98,6 +98,9 @@ main { list-style: none; display: inline-block; } + li.unpublished { + opacity: 0.5; + } a { text-transform: uppercase; display: inline-block; diff --git a/chloro/phyll/templates/phyll/note_list.html b/chloro/phyll/templates/phyll/note_list.html index abc30a0..aedf918 100644 --- a/chloro/phyll/templates/phyll/note_list.html +++ b/chloro/phyll/templates/phyll/note_list.html @@ -8,7 +8,7 @@

{{ view.kwargs.tag }}

diff --git a/chloro/phyll/views.py b/chloro/phyll/views.py index f645f39..b8598dc 100644 --- a/chloro/phyll/views.py +++ b/chloro/phyll/views.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from django.core.exceptions import PermissionDenied from django.http import Http404 from django.views.generic import CreateView, DeleteView, DetailView, ListView, UpdateView, TemplateView @@ -24,9 +25,9 @@ class NoteView(DetailView): model = Note def get(self, request, *args, **kwargs): + note = self.get_object() if kwargs.get('year'): # check date does match - note = self.get_object() creation = self.get_object().creation_timestamp if (creation.year, creation.month, creation.day) != ( int(kwargs['year']), @@ -34,17 +35,19 @@ class NoteView(DetailView): int(kwargs['day']), ): raise Http404() + if not note.published and not request.user.is_staff: + raise PermissionDenied() return super(NoteView, self).get(request, *args, **kwargs) class NoteEditView(UpdateView): model = Note - fields = ['title', 'slug', 'text', 'tags'] + fields = ['title', 'slug', 'text', 'tags', 'published'] class NoteAddView(CreateView): model = Note - fields = ['title', 'slug', 'text', 'tags'] + fields = ['title', 'slug', 'text', 'tags', 'published'] class NoteDeleteView(DeleteView): @@ -62,4 +65,7 @@ class ListOnTagView(ListView): model = Note def get_queryset(self): - return Note.objects.filter(tags__name__in=[self.kwargs['tag']]) + qs = Note.objects.filter(tags__name__in=[self.kwargs['tag']]) + if not self.request.user.is_staff: + qs = qs.filter(published=True) + return qs -- 2.39.2