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 NewsboxPublishedMixinView(object):
def get_queryset(self):
queryset = super(NewsboxPublishedMixinView, self).get_queryset()
if not self.model.has_change_permission(self.request.user):
queryset = queryset.filter(self.model.q_published())
return queryset
class NewsboxBaseArchiveView(NewsboxPublishedMixinView):
"""
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']
title = self.model._meta.verbose_name_plural.capitalize()
else:
context.update({
'instance': None,
'title': title,
'title_url': '',
class NewsboxArchiveView(NewsboxBaseArchiveView, ArchiveIndexView):
class NewsboxYearArchiveView(NewsboxBaseArchiveView, YearArchiveView):
class NewsboxMonthArchiveView(NewsboxBaseArchiveView, MonthArchiveView):
month_format = "%m"
class NewsboxDayArchiveView(NewsboxBaseArchiveView, DayArchiveView):
month_format = "%m"
class NewsboxDetailView(NewsboxPublishedMixinView, 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)