summaryrefslogtreecommitdiff
path: root/app/fieldnotes/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/fieldnotes/views.py')
-rw-r--r--app/fieldnotes/views.py35
1 files changed, 31 insertions, 4 deletions
diff --git a/app/fieldnotes/views.py b/app/fieldnotes/views.py
index 9b49cc0..d9d1526 100644
--- a/app/fieldnotes/views.py
+++ b/app/fieldnotes/views.py
@@ -1,17 +1,44 @@
+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
"""
- Return a list of Notes in reverse chronological order
+ Main Archive of Field Notes, which also includes photo posts
"""
- queryset = FieldNote.objects.filter(status=1).order_by('-pub_date')
+ model = FieldNote
+ template_name = "fieldnotes/fieldnote_list.html"
+
+ def dispatch(self, request, *args, **kwargs):
+ path = request.path.split('/')[1:-1]
+ if int(path[-1]) == self.kwargs['page']:
+ path = "/".join(t for t in path[:-1])
+ print(path)
+ 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="daily_").prefetch_related('sizes').prefetch_related('location')
+ result_list = sorted(
+ chain(qs1, qs2),
+ key=attrgetter('pub_date')
+ )
+ return result_list[:: -1]
class FieldNoteDetailView(LuxDetailView):