from django.views.generic import ListView from django.views.generic.detail import DetailView from django.views.generic.dates import YearArchiveView, MonthArchiveView from django.contrib.syndication.views import Feed from django.conf import settings from utils.views import PaginatedListView from .models import Entry, HomepageCurrator from daily.models import CheckIn from locations.models import Country, Region class EntryList(PaginatedListView): """ Return a list of Entries in reverse chronological order """ queryset = Entry.objects.filter(status__exact=1).order_by('-pub_date').select_related() template_name = "archives/writing.html" class EntryCountryList(PaginatedListView): """ Return a list of Entries by Country in reverse chronological order """ template_name = "archives/writing.html" def get_context_data(self, **kwargs): # Call the base implementation first to get a context context = super(EntryCountryList, self).get_context_data(**kwargs) try: context['region'] = Country.objects.get(slug__exact=self.kwargs['slug']) except: context['region'] = Region.objects.get(slug__exact=self.kwargs['slug']) return context def get_queryset(self): try: region = Country.objects.get(slug__exact=self.kwargs['slug']) qs = Entry.objects.filter( status__exact=1, location__state__country=region ).order_by('-pub_date') except: region = Region.objects.get(slug__exact=self.kwargs['slug']) qs = Entry.objects.filter( status__exact=1, location__state__country__lux_region=region.id ).order_by('-pub_date') return qs 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 EntryDetailViewTXT(EntryDetailView): template_name = "details/entry.txt" class EntryDetailViewAMP(EntryDetailView): template_name = "details/entry.amp" class HomepageList(ListView): """ Return a main entry and list of Entries in reverse chronological order """ context_object_name = 'recent' exclude = HomepageCurrator.objects.get(pk=1) queryset = Entry.objects.filter(status__exact=1).exclude(pk=exclude.featured.pk)[:8] 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['location'] = CheckIn.objects.get(pk=1) context['IMAGES_URL'] = settings.IMAGES_URL return context class JrnlRSSFeedView(Feed): title = "Luxagraf: Topographical Writings" link = "/jrnl/" description = "Latest postings to luxagraf.net" description_template = 'feeds/blog_description.html' def items(self): return Entry.objects.filter(status__exact=1).order_by('-pub_date')[:10]