diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/fieldnotes/templates/fieldnotes/fieldnote_archive_list_date.html | 1 | ||||
-rw-r--r-- | app/fieldnotes/urls.py | 14 | ||||
-rw-r--r-- | app/fieldnotes/views.py | 56 |
3 files changed, 56 insertions, 15 deletions
diff --git a/app/fieldnotes/templates/fieldnotes/fieldnote_archive_list_date.html b/app/fieldnotes/templates/fieldnotes/fieldnote_archive_list_date.html index 57bbb69..5d6865f 100644 --- a/app/fieldnotes/templates/fieldnotes/fieldnote_archive_list_date.html +++ b/app/fieldnotes/templates/fieldnotes/fieldnote_archive_list_date.html @@ -1,7 +1,6 @@ {% extends 'base.html' %} {% load typogrify_tags %} {% load html5_datetime %} -{% load pagination_tags %} {% block pagetitle %} Field Notes | luxagraf {% endblock %} {% block metadescription %} Rough notes and sketches from the field {% endblock %} {%block bodyid%}id="field-notes"{%endblock%} diff --git a/app/fieldnotes/urls.py b/app/fieldnotes/urls.py index 52fb6fe..afda6f9 100644 --- a/app/fieldnotes/urls.py +++ b/app/fieldnotes/urls.py @@ -5,6 +5,12 @@ from . import views app_name = "field notes" urlpatterns = [ + re_path( + r'(?P<year>[0-9]{4})/$', + views.FieldNoteYearArchiveView.as_view(), + {'page': 1}, + name="list_year" + ), path( r'', views.FieldNoteListView.as_view(), @@ -28,12 +34,8 @@ urlpatterns = [ ), path( r'<int:year>/<int:month>/', - views.FieldNoteMonthArchiveView.as_view(month_format='%m'), + views.FieldNoteMonthArchiveView.as_view(), + {'page': 1}, name="list_month" ), - re_path( - r'(?P<year>[0-9]{4})/$', - views.FieldNoteYearArchiveView.as_view(), - name="list_year" - ), ] diff --git a/app/fieldnotes/views.py b/app/fieldnotes/views.py index f22cfeb..d9b05b2 100644 --- a/app/fieldnotes/views.py +++ b/app/fieldnotes/views.py @@ -8,6 +8,7 @@ from utils.views import PaginatedListView, LuxDetailView from .models import FieldNote from photos.models import LuxImage + class FieldNoteListView(PaginatedListView): """ Main Archive of Field Notes, which also includes photo posts @@ -49,15 +50,54 @@ class FieldNoteDetailViewTXT(FieldNoteDetailView): template_name = "jrnl/entry.txt" -class FieldNoteYearArchiveView(YearArchiveView): - queryset = FieldNote.objects.filter(status=1) - date_field = "pub_date" +class FieldNoteYearArchiveView(FieldNoteListView): template_name = "fieldnotes/fieldnote_archive_list_date.html" - make_object_list = True + + def get_queryset(self): + """ + Return a list of Notes and Photos combined + in reverse chronological order + """ + qs1 = FieldNote.objects.filter( + status=1, + pub_date__year=self.kwargs['year'], + ).order_by('-pub_date').prefetch_related('location') + qs2 = LuxImage.objects.filter( + is_public=True, + title__startswith="fn_", + pub_date__year=self.kwargs['year'], + ).prefetch_related('sizes').prefetch_related('location') + result_list = sorted( + chain(qs1, qs2), + key=attrgetter('pub_date') + ) + return result_list[:: -1] -class FieldNoteMonthArchiveView(MonthArchiveView): - queryset = FieldNote.objects.filter(status=1) - date_field = "pub_date" - make_object_list = True +class FieldNoteMonthArchiveView(FieldNoteListView): template_name = "fieldnotes/fieldnote_archive_list_date.html" + + + def get_queryset(self): + """ + Return a list of Notes and Photos combined + in reverse chronological order + """ + qs1 = FieldNote.objects.filter( + status=1, + pub_date__year=self.kwargs['year'], + pub_date__month=self.kwargs['month'] + ).order_by('-pub_date').prefetch_related('location') + qs2 = LuxImage.objects.filter( + is_public=True, + title__startswith="fn_", + pub_date__year=self.kwargs['year'], + pub_date__month=self.kwargs['month'] + ).prefetch_related('sizes').prefetch_related('location') + + result_list = sorted( + chain(qs1, qs2), + key=attrgetter('pub_date') + ) + return result_list[:: -1] + |