]> git.0d.be Git - chloro.git/commitdiff
views: add page to list notes by tag
authorFrédéric Péters <fpeters@0d.be>
Sun, 29 Dec 2019 17:23:20 +0000 (18:23 +0100)
committerFrédéric Péters <fpeters@0d.be>
Mon, 30 Dec 2019 08:35:50 +0000 (09:35 +0100)
chloro/phyll/migrations/0002_auto_20191229_1932.py [new file with mode: 0644]
chloro/phyll/models.py
chloro/phyll/templates/phyll/note_list.html [new file with mode: 0644]
chloro/phyll/urls.py
chloro/phyll/views.py

diff --git a/chloro/phyll/migrations/0002_auto_20191229_1932.py b/chloro/phyll/migrations/0002_auto_20191229_1932.py
new file mode 100644 (file)
index 0000000..5650df4
--- /dev/null
@@ -0,0 +1,16 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.17 on 2019-12-29 18:32
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('phyll', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(name='note', options={'ordering': ['-creation_timestamp']},),
+    ]
index b8872c4d61b8d0f5d6f732069e53f7581c97ace8..230738930d3be022e583bdfde77b5ddb6b141af0 100644 (file)
@@ -29,5 +29,8 @@ class Note(models.Model):
     creation_timestamp = models.DateTimeField(auto_now_add=True)
     last_update_timestamp = models.DateTimeField(auto_now=True)
 
+    class Meta:
+        ordering = ['-creation_timestamp']
+
     def get_absolute_url(self):
         return '/%s/' % self.slug
diff --git a/chloro/phyll/templates/phyll/note_list.html b/chloro/phyll/templates/phyll/note_list.html
new file mode 100644 (file)
index 0000000..abc30a0
--- /dev/null
@@ -0,0 +1,20 @@
+{% extends "phyll/base.html" %}
+{% load i18n %}
+
+{% block content-class %}post-list{% endblock %}
+
+{% block body %}
+<div>
+<h2>{{ view.kwargs.tag }}</h2>
+<ul>
+{% for post in object_list %}
+<li><a href="{{ post.get_absolute_url }}">{{ post.title }} <span>{{ post.creation_timestamp|date:"Y/m/d" }}</a></li>
+{% endfor %}
+</ul>
+</div>
+{% endblock %}
+
+{% block bottom-actions %}
+<a href="edit/">{% trans "Edit" %}</a>
+<a href="delete/">{% trans "Delete" %}</a>
+{% endblock %}
index 14188107cd618c53a4cc6d0566bddd6eca886b79..13c70bae5c5626764be016c64e7657650a311a97 100644 (file)
@@ -39,6 +39,7 @@ urlpatterns = [
         staff_member_required(views.NoteDeleteView.as_view(), login_url='login'),
     ),
     url(r'^new-note/$', staff_member_required(views.NoteAddView.as_view(), login_url='login')),
+    url(r'^tag/(?P<tag>[\w:-]+)/$', views.ListOnTagView.as_view()),
     url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[\w:-]+)/$', views.NoteView.as_view()),
     url(r'^(?P<slug>[\w:-]+)/$', views.NoteView.as_view()),
     url(r'^$', views.HomeView.as_view()),
index 5387b705e5805550f47bdbd82fc2ecb28cbc1583..f645f39bfba269f9ae8993f4581351a008b053b6 100644 (file)
@@ -15,7 +15,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from django.http import Http404
-from django.views.generic import CreateView, DeleteView, DetailView, UpdateView, TemplateView
+from django.views.generic import CreateView, DeleteView, DetailView, ListView, UpdateView, TemplateView
 
 from .models import Note
 
@@ -56,3 +56,10 @@ class NoteDeleteView(DeleteView):
 
 class HomeView(TemplateView):
     template_name = 'phyll/home.html'
+
+
+class ListOnTagView(ListView):
+    model = Note
+
+    def get_queryset(self):
+        return Note.objects.filter(tags__name__in=[self.kwargs['tag']])