summaryrefslogtreecommitdiff
path: root/app/jrnl/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/jrnl/views.py')
-rw-r--r--app/jrnl/views.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/app/jrnl/views.py b/app/jrnl/views.py
new file mode 100644
index 0000000..7dd755b
--- /dev/null
+++ b/app/jrnl/views.py
@@ -0,0 +1,89 @@
+from django.views.generic import ListView
+from django.views.generic.detail import DetailView
+from django.views.generic.dates import YearArchiveView, MonthArchiveView
+
+from django.conf import settings
+
+from .models import Entry, HomepageCurrator
+
+from locations.models import Country
+
+
+class EntryList(ListView):
+ """
+ Return a list of Entries in reverse chronological order
+ """
+ context_object_name = 'object_list'
+ queryset = Entry.objects.filter(status__exact=1).order_by('-pub_date').select_related()
+ template_name = "archives/writing.html"
+
+ def dispatch(self, request, *args, **kwargs):
+ request.page_url = '/jrnl/%d/'
+ request.page = int(self.kwargs['page'])
+ return super(EntryList, self).dispatch(request, *args, **kwargs)
+
+
+class EntryCountryList(ListView):
+ """
+ Return a list of Entries by Country in reverse chronological order
+ """
+ context_object_name = 'object_list'
+ template_name = "archives/writing.html"
+
+ def dispatch(self, request, *args, **kwargs):
+ request.page_url = '/jrnl/' + self.kwargs['slug'] + '/%d/'
+ request.page = int(self.kwargs['page'])
+ return super(EntryCountryList, self).dispatch(request, *args, **kwargs)
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(EntryCountryList, self).get_context_data(**kwargs)
+ context['region'] = Country.objects.get(slug__exact=self.kwargs['slug'])
+ return context
+
+ def get_queryset(self):
+ country = Country.objects.get(slug__exact=self.kwargs['slug'])
+ return Entry.objects.filter(
+ status__exact=1,
+ location__state__country=country
+ ).order_by('-pub_date')
+
+
+class EntryYearArchiveView(YearArchiveView):
+ queryset = Entry.objects.filter(status__exact=1).select_related()
+ date_field = "pub_date"
+ make_object_list = True
+ allow_future = True
+ template_name = "archives/writing_date.html"
+
+
+class EntryMonthArchiveView(MonthArchiveView):
+ queryset = Entry.objects.filter(status__exact=1).select_related()
+ date_field = "pub_date"
+ allow_future = True
+ template_name = "archives/writing_date.html"
+
+
+class EntryDetailView(DetailView):
+ model = Entry
+ template_name = "details/entry.html"
+ slug_field = "slug"
+
+
+class HomepageList(ListView):
+ """
+ Return a main entry and list of Entries in reverse chronological order
+ """
+ context_object_name = 'recent'
+ queryset = Entry.objects.filter(status__exact=1)[:4]
+
+ def get_template_names(self):
+ obj = HomepageCurrator.objects.get(pk=1)
+ return ['%s' % obj.template_name]
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(HomepageList, self).get_context_data(**kwargs)
+ context['homepage'] = HomepageCurrator.objects.get(pk=1)
+ context['IMAGES_URL'] = settings.IMAGES_URL
+ return context