]> git.p6c8.net - pcdenotes.git/commitdiff
Began to implement archive view
authorPatrick Canterino <patrick@patrick-canterino.de>
Sun, 30 Jan 2022 13:08:31 +0000 (14:08 +0100)
committerPatrick Canterino <patrick@patrick-canterino.de>
Sun, 30 Jan 2022 13:08:31 +0000 (14:08 +0100)
You can already list the years

.gitignore
notes/templates/archive_main.html [new file with mode: 0644]
notes/templates/archive_month.html [new file with mode: 0644]
notes/templates/archive_year.html [new file with mode: 0644]
notes/urls.py
notes/views.py

index fcc7e9b5f54ed482ba8775ce2a03aacf73e7f17f..7941172fa77ac56eec52be0c29ac510f84fc2b9d 100644 (file)
@@ -1,4 +1,4 @@
-.env
+.env*
 .venv
 __pycache__
 db.sqlite3
diff --git a/notes/templates/archive_main.html b/notes/templates/archive_main.html
new file mode 100644 (file)
index 0000000..268e950
--- /dev/null
@@ -0,0 +1,17 @@
+{% extends "note_base.html" %}
+
+{% block title %}Archive – Notes{% endblock %}
+
+{% block content %}
+<h2>Archive</h2>
+
+{% if years %}
+<ul>
+  {% for year in years %}
+    <li><a href="{{ year }}/">{{ year }}</a></li>
+  {% endfor %}
+</ul>
+{% else %}
+<p>No notes</p>
+{% endif %}
+{% endblock %}
\ No newline at end of file
diff --git a/notes/templates/archive_month.html b/notes/templates/archive_month.html
new file mode 100644 (file)
index 0000000..ced8896
--- /dev/null
@@ -0,0 +1,9 @@
+{% extends "note_base.html" %}
+
+{% block title %}Archive {{ month }} / {{ year }} – Notes{% endblock %}
+
+{% block content %}
+<h2>Archive {{ month }} / {{ year }}</h2>
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/notes/templates/archive_year.html b/notes/templates/archive_year.html
new file mode 100644 (file)
index 0000000..ec64328
--- /dev/null
@@ -0,0 +1,9 @@
+{% extends "note_base.html" %}
+
+{% block title %}Archive {{ year }} – Notes{% endblock %}
+
+{% block content %}
+<h2>Archive {{ year }}</h2>
+
+
+{% endblock %}
\ No newline at end of file
index 560e8f5a3670b0b99ebbbc8839c52464999fa9f7..9a200539fa405161398303db5e9143eefb162947 100644 (file)
@@ -7,4 +7,7 @@ urlpatterns=[
     path('', views.note_list, name='note_list'),
     re_path('^notes/?$', views.note_redirect, name='note_redirect'),
     path('notes/<slug:note_slug>', views.note_detail, name='note_detail'),
+    path('archive/', views.archive_main, name='archive_main'),
+    path('archive/<int:archive_year>/', views.archive_year, name='archive_year'),
+    path('archive/<int:archive_year>/<int:archive_month>/', views.archive_month, name='archive_month'),
 ]
\ No newline at end of file
index bd2fd8208147108c35552f710750de364b8e66ac..18946bf5810edfdb422df3c47029b35ff7e88993 100644 (file)
@@ -1,5 +1,6 @@
 from django.shortcuts import render, get_object_or_404, redirect
 from django.core.paginator import Paginator
+from django.db.models.functions import ExtractYear
 
 from pcdenotes.settings import NOTES_PER_PAGE
 from .models import Note
@@ -30,4 +31,14 @@ def note_redirect(request):
 
 def note_detail(request, note_slug):
     note = get_object_or_404(Note, slug=note_slug) if request.user.is_staff else get_object_or_404(Note, slug=note_slug, status=1)
-    return render(request, 'note_detail.html', {'note': note})
\ No newline at end of file
+    return render(request, 'note_detail.html', {'note': note})
+
+def archive_main(request):
+    notes_years = Note.objects.all().annotate(created_year=ExtractYear('created_at')).values_list('created_year', flat=True).distinct().order_by('created_year')
+    return render(request, 'archive_main.html', {'years': notes_years})
+
+def archive_year(request, archive_year):
+    return render(request, 'archive_year.html', {'year': archive_year})
+
+def archive_month(request, archive_year, archive_month):
+    return render(request, 'archive_month.html', {'year': archive_year, 'month': archive_month})
\ No newline at end of file

patrick-canterino.de