Files
@ 2bf594b86cb1
Branch filter:
Location: website/www/conservancy/apps/news/views.py - annotation
2bf594b86cb1
3.9 KiB
text/x-python
First pass at migration to Django 1.7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 f7e45da6ddc8 f7e45da6ddc8 8e6ea8ad71bf 2bf594b86cb1 2bf594b86cb1 8e6ea8ad71bf 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 8e6ea8ad71bf 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 2bf594b86cb1 | # from django.views.generic.list_detail import object_list
from django.views.generic import ListView
from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView
from conservancy.apps.news.models import ExternalArticle
from conservancy.apps.events.models import Event
from datetime import datetime
# for debugging...
from django.http import HttpResponse
class NewsListView(ListView):
extra_context = {}
def get_context_data(self, **kwargs):
context = super(NewsListView, self).get_context_data(**kwargs)
# context['key'] = 'value'
context.update(self.extra_context)
return context
def custom_index(request, queryset, *args, **kwargs):
"""News index. Calls a generic list view, but passes additional
context including past and future events, and an index of news by
year.
"""
# debug = '<pre>This is news'
# debug += '\nqueryset: ' + str(queryset)
# debug += '\nargs: ' + str(args)
# debug += '\nkwargs: ' + str(kwargs)
# debug += '</pre>'
# return HttpResponse(debug)
articles = None
#if not request.GET.has_key("page"):
# articles = ExternalArticle.public.all().order_by("-date")[:10]
if (not kwargs.has_key('allow_future')) or not kwargs['allow_future']:
queryset = queryset.filter(**{'%s__lte' % kwargs['date_field']:
datetime.now()})
future_events = Event.future.all().filter(date_tentative=False).order_by("date")
past_events = Event.past.all().order_by("-date")[:6]
date_list = queryset.dates(kwargs['date_field'], 'year')
kwargs = dict(kwargs, extra_context={'articles': articles,
'date_list': date_list,
'future_events': future_events,
'past_events': past_events})
del kwargs['date_field']
# return object_list(request, queryset, *args, **kwargs)
# callable = NewsListView.as_view(queryset=queryset,
# extra_context=kwargs,
# paginate_by=kwargs['paginate_by'])
kwargs['queryset'] = queryset
callable = NewsListView.as_view(**kwargs)
return callable(request)
# num_navigation = 3 # in each direction
# page_navigation = range(max((page - num_navigation), 1),
# min((page + num_navigation), page_count) + 1)
class NewsYearArchiveView(YearArchiveView):
# queryset = Article.objects.all()
# date_field = "pub_date"
make_object_list = True
allow_future = True
# def archive_year(request, **kwargs):
# callable = NewsYearArchiveView.as_view(**kwargs)
# return callable(request)
class NewsMonthArchiveView(MonthArchiveView):
allow_future = True
# def archive_month(request, **kwargs):
# # return HttpResponse("archive_month")
# callable = NewsMonthArchiveView.as_view(**kwargs)
# return callable(request)
class NewsDayArchiveView(DayArchiveView):
allow_future = True
# def archive_day(request, **kwargs):
# # return HttpResponse("archive_day")
# callable = NewsDayArchiveView.as_view(**kwargs)
# return callable(request)
class NewsDateDetailView(DateDetailView):
# extra_context = {}
allow_future = True
# slug_url_kwarg = 'slug'
# def get_context_data(self, **kwargs):
# context = super(NewsDateDetailView, self).get_context_data(**kwargs)
# context.update(self.extra_context)
# return context
# def object_detail(request, **kwargs):
# # extra_context = {}
# # extra_context['slug'] = kwargs['slug']
# # del kwargs['slug']
# # kwargs['extra_context'] = extra_context
# # return HttpResponse("object_detail: " + str(kwargs))
# # slug = kwargs['slug']
# # del kwargs['slug']
# callable = NewsDateDetailView.as_view(**kwargs)
# return callable(request)
|