2023-10-19 22:44:24 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
2015-03-03 18:40:18 +00:00
|
|
|
from django.views.generic import ListView
|
2017-11-03 15:58:24 +00:00
|
|
|
from django.shortcuts import render
|
2015-03-03 18:40:18 +00:00
|
|
|
from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView
|
2015-03-04 19:30:51 +00:00
|
|
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
2015-03-03 18:40:18 +00:00
|
|
|
from django.http import HttpResponse
|
2010-09-26 21:32:53 +00:00
|
|
|
|
2023-10-19 22:44:24 +00:00
|
|
|
from .models import ExternalArticle
|
|
|
|
from .models import PressRelease
|
|
|
|
from ..events.models import Event
|
|
|
|
|
2015-03-03 18:40:18 +00:00
|
|
|
|
|
|
|
class NewsListView(ListView):
|
|
|
|
extra_context = {}
|
|
|
|
def get_context_data(self, **kwargs):
|
2023-09-07 13:15:48 +00:00
|
|
|
context = super().get_context_data(**kwargs)
|
2015-03-03 18:40:18 +00:00
|
|
|
# context['key'] = 'value'
|
|
|
|
context.update(self.extra_context)
|
|
|
|
return context
|
|
|
|
|
2015-03-04 20:30:54 +00:00
|
|
|
def listing(request, *args, **kwargs):
|
2015-03-04 20:22:33 +00:00
|
|
|
news_queryset = PressRelease.objects.all()
|
2015-03-04 20:08:39 +00:00
|
|
|
|
|
|
|
# if (not kwargs.has_key('allow_future')) or not kwargs['allow_future']:
|
2015-03-04 20:22:33 +00:00
|
|
|
news_queryset = news_queryset.filter(**{'%s__lte' % kwargs['date_field']:
|
2015-03-04 20:08:39 +00:00
|
|
|
datetime.now()})
|
|
|
|
|
2015-03-04 20:33:12 +00:00
|
|
|
date_list = news_queryset.dates(kwargs['date_field'], 'year')
|
2015-03-04 20:08:39 +00:00
|
|
|
|
2015-03-04 20:30:54 +00:00
|
|
|
paginate_by = kwargs.get('paginate_by', 6) # Show 6 news items per page, by default
|
|
|
|
paginator = Paginator(news_queryset, paginate_by)
|
2015-03-04 20:08:39 +00:00
|
|
|
|
|
|
|
page = request.GET.get('page')
|
|
|
|
try:
|
2015-03-04 20:22:33 +00:00
|
|
|
news = paginator.page(page)
|
2015-03-04 20:08:39 +00:00
|
|
|
except PageNotAnInteger:
|
|
|
|
# If page is not an integer, deliver first page.
|
2015-03-04 20:22:33 +00:00
|
|
|
news = paginator.page(1)
|
2015-03-04 20:08:39 +00:00
|
|
|
except EmptyPage:
|
|
|
|
# If page is out of range (e.g. 9999), deliver last page of results.
|
2015-03-04 20:22:33 +00:00
|
|
|
news = paginator.page(paginator.num_pages)
|
2015-03-04 20:08:39 +00:00
|
|
|
|
2017-11-03 15:58:24 +00:00
|
|
|
return render(request, 'news/pressrelease_list.html', {"news": news, "date_list" : date_list})
|
2015-03-04 20:08:39 +00:00
|
|
|
|
2015-03-03 18:40:18 +00:00
|
|
|
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)
|
|
|
|
|