forked from rc/aircox
static pages
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
from ..models import Article, Program
|
||||
from .mixins import ParentMixin
|
||||
from ..models import Article, Program, StaticPage
|
||||
from .page import PageDetailView, PageListView
|
||||
|
||||
|
||||
@ -17,12 +16,12 @@ class ArticleDetailView(PageDetailView):
|
||||
return qs
|
||||
|
||||
|
||||
class ArticleListView(ParentMixin, PageListView):
|
||||
class ArticleListView(PageListView):
|
||||
model = Article
|
||||
template_name = 'aircox/article_list.html'
|
||||
has_headline = True
|
||||
is_static = False
|
||||
parent_model = Program
|
||||
attach_to_value = StaticPage.ATTACH_TO_ARTICLES
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(is_static=self.is_static)
|
||||
|
@ -12,11 +12,6 @@ __all__ = ['BaseView']
|
||||
|
||||
|
||||
class BaseView(TemplateResponseMixin, ContextMixin):
|
||||
title = None
|
||||
""" Page title """
|
||||
cover = None
|
||||
""" Page cover """
|
||||
|
||||
has_sidebar = True
|
||||
""" Show side navigation """
|
||||
has_filters = False
|
||||
@ -39,9 +34,12 @@ class BaseView(TemplateResponseMixin, ContextMixin):
|
||||
def get_sidebar_url(self):
|
||||
return reverse('page-list')
|
||||
|
||||
def get_page(self):
|
||||
return None
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs.setdefault('station', self.station)
|
||||
kwargs.setdefault('cover', self.cover)
|
||||
kwargs.setdefault('page', self.get_page())
|
||||
kwargs.setdefault('has_filters', self.has_filters)
|
||||
|
||||
has_sidebar = kwargs.setdefault('has_sidebar', self.has_sidebar)
|
||||
@ -61,7 +59,6 @@ class BaseView(TemplateResponseMixin, ContextMixin):
|
||||
type(self.object)
|
||||
kwargs['model'] = model
|
||||
|
||||
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
|
@ -4,11 +4,11 @@ import datetime
|
||||
from django.views.generic import ListView
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from ..models import Diffusion, Episode, Program, Sound
|
||||
from ..models import Diffusion, Episode, Program, StaticPage, Sound
|
||||
from .base import BaseView
|
||||
from .program import ProgramPageDetailView
|
||||
from .page import PageListView
|
||||
from .mixins import GetDateMixin, ParentMixin
|
||||
from .mixins import AttachedToMixin, GetDateMixin, ParentMixin
|
||||
|
||||
|
||||
__all__ = ['EpisodeDetailView', 'EpisodeListView', 'DiffusionListView']
|
||||
@ -28,18 +28,20 @@ class EpisodeDetailView(ProgramPageDetailView):
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class EpisodeListView(ParentMixin, PageListView):
|
||||
class EpisodeListView(PageListView):
|
||||
model = Episode
|
||||
item_template_name = 'aircox/widgets/episode_item.html'
|
||||
has_headline = True
|
||||
parent_model = Program
|
||||
attach_to_value = StaticPage.ATTACH_TO_EPISODES
|
||||
|
||||
|
||||
class DiffusionListView(GetDateMixin, BaseView, ListView):
|
||||
class DiffusionListView(GetDateMixin, AttachedToMixin, BaseView, ListView):
|
||||
""" View for timetables """
|
||||
model = Diffusion
|
||||
has_filters = True
|
||||
redirect_date_url = 'diffusion-list'
|
||||
attach_to_value = StaticPage.ATTACH_TO_DIFFUSIONS
|
||||
|
||||
def get_date(self):
|
||||
date = super().get_date()
|
||||
|
@ -3,9 +3,10 @@ import datetime
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils import timezone as tz
|
||||
|
||||
from ..models import Diffusion, Log, Page
|
||||
from ..models import Diffusion, Log, Page, StaticPage
|
||||
from .page import PageListView
|
||||
|
||||
|
||||
class HomeView(PageListView):
|
||||
template_name = 'aircox/home.html'
|
||||
model = Page
|
||||
@ -14,6 +15,7 @@ class HomeView(PageListView):
|
||||
list_count = 40
|
||||
logs_count = 5
|
||||
has_filters = False
|
||||
attach_to_value = StaticPage.ATTACH_TO_HOME
|
||||
|
||||
def get_logs(self):
|
||||
today = datetime.date.today()
|
||||
|
@ -8,10 +8,10 @@ from rest_framework.generics import ListAPIView
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.decorators import action
|
||||
|
||||
from ..models import Diffusion, Log
|
||||
from ..models import Diffusion, Log, StaticPage
|
||||
from ..serializers import LogInfo, LogInfoSerializer
|
||||
from .base import BaseView, BaseAPIView
|
||||
from .mixins import GetDateMixin
|
||||
from .mixins import GetDateMixin, AttachedToMixin
|
||||
|
||||
|
||||
__all__ = ['LogListMixin', 'LogListView']
|
||||
@ -52,13 +52,14 @@ class LogListMixin(GetDateMixin):
|
||||
return Log.merge_diffusions(logs, diffs)
|
||||
|
||||
|
||||
class LogListView(BaseView, LogListMixin, ListView):
|
||||
class LogListView(AttachedToMixin, BaseView, LogListMixin, ListView):
|
||||
"""
|
||||
Return list of logs for the provided date (from `kwargs` or
|
||||
`request.GET`, defaults to today).
|
||||
"""
|
||||
redirect_date_url = 'log-list'
|
||||
has_filters = True
|
||||
attach_to_value = StaticPage.ATTACH_TO_LOGS
|
||||
|
||||
def get_date(self):
|
||||
date = super().get_date()
|
||||
|
@ -2,9 +2,10 @@ from django.shortcuts import get_object_or_404, redirect
|
||||
from django.urls import reverse
|
||||
|
||||
from ..utils import str_to_date
|
||||
from ..models import StaticPage
|
||||
|
||||
|
||||
__all__ = ['GetDateMixin', 'ParentMixin']
|
||||
__all__ = ['GetDateMixin', 'ParentMixin', 'AttachedToMixin']
|
||||
|
||||
|
||||
class GetDateMixin:
|
||||
@ -68,3 +69,14 @@ class ParentMixin:
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class AttachedToMixin:
|
||||
""" Mixin for views that can have a static page attached to it. """
|
||||
attach_to_value = None
|
||||
""" Value of StaticPage.attach_to """
|
||||
|
||||
def get_page(self):
|
||||
if self.attach_to_value is not None:
|
||||
return StaticPage.objects.filter(attach_to=self.attach_to_value) \
|
||||
.published().first()
|
||||
return super().get_page()
|
||||
|
||||
|
@ -6,15 +6,16 @@ from django.views.generic import DetailView, ListView
|
||||
from honeypot.decorators import check_honeypot
|
||||
|
||||
from ..forms import CommentForm
|
||||
from ..models import Category, Comment, Page
|
||||
from ..models import Category, Comment
|
||||
from ..utils import Redirect
|
||||
from .base import BaseView
|
||||
from .mixins import AttachedToMixin, ParentMixin
|
||||
|
||||
|
||||
__all__ = ['PageDetailView', 'PageListView']
|
||||
|
||||
|
||||
class PageListView(BaseView, ListView):
|
||||
class PageListView(AttachedToMixin, ParentMixin, BaseView, ListView):
|
||||
template_name = 'aircox/page_list.html'
|
||||
item_template_name = 'aircox/widgets/page_item.html'
|
||||
has_sidebar = True
|
||||
@ -81,14 +82,12 @@ class PageDetailView(BaseView, DetailView):
|
||||
raise Http404('%s not found' % self.model._meta.verbose_name)
|
||||
return obj
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
page = kwargs.setdefault('page', self.object)
|
||||
kwargs.setdefault('title', page.title)
|
||||
kwargs.setdefault('cover', page.cover)
|
||||
def get_page(self):
|
||||
return self.object
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
if self.object.allow_comments and not 'comment_form' in kwargs:
|
||||
kwargs['comment_form'] = CommentForm()
|
||||
|
||||
kwargs['comments'] = Comment.objects.filter(page=self.object) \
|
||||
.order_by('-date')
|
||||
return super().get_context_data(**kwargs)
|
||||
@ -112,5 +111,3 @@ class PageDetailView(BaseView, DetailView):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -3,8 +3,8 @@ from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
|
||||
from ..models import Episode, Program, Page
|
||||
from .mixins import ParentMixin
|
||||
from ..models import Episode, Program, Page, StaticPage
|
||||
from .mixins import ParentMixin, AttachedToMixin
|
||||
from .page import PageDetailView, PageListView
|
||||
|
||||
|
||||
@ -34,8 +34,10 @@ class ProgramDetailView(BaseProgramMixin, PageDetailView):
|
||||
|
||||
class ProgramListView(PageListView):
|
||||
model = Program
|
||||
attach_to_value = StaticPage.ATTACH_TO_PROGRAMS
|
||||
|
||||
|
||||
# FIXME: not used
|
||||
class ProgramPageDetailView(BaseProgramMixin, ParentMixin, PageDetailView):
|
||||
"""
|
||||
Base view class for a page that is displayed as a program's child page.
|
||||
@ -50,7 +52,7 @@ class ProgramPageDetailView(BaseProgramMixin, ParentMixin, PageDetailView):
|
||||
return super().get_sidebar_queryset().filter(parent=self.program)
|
||||
|
||||
|
||||
class ProgramPageListView(BaseProgramMixin, ParentMixin, PageListView):
|
||||
class ProgramPageListView(BaseProgramMixin, PageListView):
|
||||
model = Page
|
||||
parent_model = Program
|
||||
queryset = Page.objects.select_subclasses()
|
||||
|
Reference in New Issue
Block a user