Newer
Older
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.views.generic.dates import DateDetailView, ArchiveIndexView, \
YearArchiveView, MonthArchiveView, DayArchiveView
from .models import NewsboxSEOBase, NewsboxExpiredBase
class NewsboxBaseArchiveView(object):
"""
This view is responsible for displaying a list of newsbox
"""
date_field = "newsbox_publication_start_date"
slug_field = "newsbox_slug"
paginate_by = 10
make_object_list = True
allow_future = True
template_name = "newsbox/list.html"
context_object_name = 'newsset'
title = None
def get_context_data(self, *args, **kwargs):
context = super(NewsboxBaseArchiveView, self).get_context_data(*args, **kwargs)
with_pager = context['is_paginated']
context['newsset'].number = context['page_obj'].number
context['newsset'].has_previous = context['page_obj'].has_previous
context['newsset'].has_next = context['page_obj'].has_next
context['newsset'].next_page_number = context['page_obj'].next_page_number
context['newsset'].previous_page_number = context['page_obj'].previous_page_number
context['newsset'].paginator = context['paginator']
if self.title == None:
title = self.model._meta.verbose_name_plural.capitalize()
else:
title=self.title
context.update({
'instance': None,
'title': title,
'title_url': '',
'newsbox_opts':self.model._newsbox_meta,
'with_pager': with_pager,
'date_list_period':self.date_list_period,
queryset = super(NewsboxBaseArchiveView, self).get_queryset()
if not self.request.user.is_staff:
queryset = queryset.filter(pk__in=self.model.objects.published())
return queryset
class NewsboxArchiveView(NewsboxBaseArchiveView, ArchiveIndexView):
class NewsboxYearArchiveView(NewsboxBaseArchiveView, YearArchiveView):
class NewsboxMonthArchiveView(NewsboxBaseArchiveView, MonthArchiveView):
month_format = "%m"
class NewsboxDayArchiveView(NewsboxBaseArchiveView, DayArchiveView):
month_format = "%m"
class NewsboxDetailView(DateDetailView):
"""
This view is responsible for displaying a newsbox
"""
month_format = "%m"
date_field = "newsbox_publication_start_date"
slug_field = "newsbox_slug"
template_name = "newsbox/detail.html"
context_object_name = "news"
allow_future = True
def get_context_data(self, **kwargs):
context = super(NewsboxDetailView, self).get_context_data(**kwargs)
if 'NewsboxCMSBase' in (base.__name__ for base in self.model.__bases__):
from menus.utils import set_language_changer
set_language_changer(self.request, self.object.get_absolute_url)

Dylann Cordel
committed
context['newsbox_seo'] = isinstance(context['news'], NewsboxSEOBase)
context['newsbox_expired'] = isinstance(context['news'], NewsboxExpiredBase)
obj = super(NewsboxDetailView, self).get_object(queryset)
if(
not obj.is_published()
and not obj.has_change_permission(self.request)
):
raise Http404
return obj