summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/fieldnotes/urls.py4
-rw-r--r--app/fieldnotes/views.py88
2 files changed, 12 insertions, 80 deletions
diff --git a/app/fieldnotes/urls.py b/app/fieldnotes/urls.py
index afda6f9..85ee710 100644
--- a/app/fieldnotes/urls.py
+++ b/app/fieldnotes/urls.py
@@ -8,7 +8,6 @@ urlpatterns = [
re_path(
r'(?P<year>[0-9]{4})/$',
views.FieldNoteYearArchiveView.as_view(),
- {'page': 1},
name="list_year"
),
path(
@@ -34,8 +33,7 @@ urlpatterns = [
),
path(
r'<int:year>/<int:month>/',
- views.FieldNoteMonthArchiveView.as_view(),
- {'page': 1},
+ views.FieldNoteMonthArchiveView.as_view(month_format='%m'),
name="list_month"
),
]
diff --git a/app/fieldnotes/views.py b/app/fieldnotes/views.py
index d9b05b2..9b49cc0 100644
--- a/app/fieldnotes/views.py
+++ b/app/fieldnotes/views.py
@@ -1,44 +1,17 @@
-from itertools import chain
-from operator import attrgetter
from django.views.generic.dates import YearArchiveView, MonthArchiveView
from django.views.generic.detail import DetailView
from utils.views import PaginatedListView, LuxDetailView
from .models import FieldNote
-from photos.models import LuxImage
class FieldNoteListView(PaginatedListView):
+ model = FieldNote
"""
- Main Archive of Field Notes, which also includes photo posts
+ Return a list of Notes in reverse chronological order
"""
- model = FieldNote
- template_name = "fieldnotes/fieldnote_list.html"
-
- def dispatch(self, request, *args, **kwargs):
- path = request.path.split('/')[1:-1]
- if path[-1] == str(self.kwargs['page']):
- path = "/".join(t for t in path[:-1])
- request.page_url = "/" + path + '/%d/'
- else:
- request.page_url = request.path + '%d/'
- request.page = int(self.kwargs['page'])
- request.base_path = path
- return super(PaginatedListView, self).dispatch(request, *args, **kwargs)
-
- def get_queryset(self):
- """
- Return a list of Notes and Photos combined
- in reverse chronological order
- """
- qs1 = FieldNote.objects.filter(status=1).order_by('-pub_date').prefetch_related('location')
- qs2 = LuxImage.objects.filter(is_public=True, title__startswith="fn_").prefetch_related('sizes').prefetch_related('location')
- result_list = sorted(
- chain(qs1, qs2),
- key=attrgetter('pub_date')
- )
- return result_list[:: -1]
+ queryset = FieldNote.objects.filter(status=1).order_by('-pub_date')
class FieldNoteDetailView(LuxDetailView):
@@ -50,54 +23,15 @@ class FieldNoteDetailViewTXT(FieldNoteDetailView):
template_name = "jrnl/entry.txt"
-class FieldNoteYearArchiveView(FieldNoteListView):
+class FieldNoteYearArchiveView(YearArchiveView):
+ queryset = FieldNote.objects.filter(status=1)
+ date_field = "pub_date"
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'],
- ).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]
+ make_object_list = True
-class FieldNoteMonthArchiveView(FieldNoteListView):
+class FieldNoteMonthArchiveView(MonthArchiveView):
+ queryset = FieldNote.objects.filter(status=1)
+ date_field = "pub_date"
+ make_object_list = True
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]
-