diff --git a/cms/sections.py b/cms/sections.py index ef028c8..68e55c2 100644 --- a/cms/sections.py +++ b/cms/sections.py @@ -57,12 +57,18 @@ class Section(View): object = None force_object = None + def add_css_class(self, css_class): + if self.css_class: + self.css_class += ' ' + css_class + else: + self.css_class = css_class + def __init__ (self, *args, **kwargs): super().__init__(*args, **kwargs) - self.css_class += 'section' if not self.css_class else ' section' + self.add_css_class('section') if type(self) != Section: - self.css_class += ' section_' + type(self).__name__.lower() + self.add_css_class('section_' + type(self).__name__.lower()) if not self.attrs: self.attrs = {} @@ -86,12 +92,14 @@ class Section(View): 'object': self.object, } - def get(self, request, object=None, **kwargs): + def get_context(self, request, object=None, **kwargs): self.object = self.force_object or object self.request = request self.kwargs = kwargs + return self.get_context_data() - context = self.get_context_data() + def get(self, request, object=None, **kwargs): + context = self.get_context(request, object, **kwargs) if not context: return '' return render_to_string(self.template_name, context, request=request) @@ -201,7 +209,10 @@ class List(Section): of ListItem. """ super().__init__(*args, **kwargs) - self.css_class += ' list' + self.add_css_class('list') + if type(self) != Section: + self.add_css_class('section_' + type(self).__name__.lower()) + if items: self.object_list = [ ListItem(item) for item in items diff --git a/cms/templates/aircox/cms/detail.html b/cms/templates/aircox/cms/detail.html index ca6eacf..08b0cd1 100644 --- a/cms/templates/aircox/cms/detail.html +++ b/cms/templates/aircox/cms/detail.html @@ -1,12 +1,8 @@ {% extends "aircox/cms/website.html" %} {% load aircox_cms %} -{% block title %} -{{ object.title }} -{% endblock %} - -{% block pre_title %} -
+{% block header %} +
{% if object.thread %}
{{ object|threads:' > '|safe }} @@ -24,7 +20,7 @@ {{ object.tags.all|join:', ' }}
{% endif %} -
+ {% endblock %} {% block content %} diff --git a/cms/templates/aircox/cms/section.html b/cms/templates/aircox/cms/section.html index a12c662..fac3ea5 100644 --- a/cms/templates/aircox/cms/section.html +++ b/cms/templates/aircox/cms/section.html @@ -6,18 +6,14 @@ {% block title %} {% if title %} -

- {{ title }} -

+

{{ title }}

{% endif %} {% endblock %} {% block header %} -{% if header %}
- {{ header|safe }} +{{ header|safe }}
-{% endif %} {% endblock %} {% block content %} diff --git a/cms/templates/aircox/cms/website.html b/cms/templates/aircox/cms/website.html index 6494dea..d09a2ef 100644 --- a/cms/templates/aircox/cms/website.html +++ b/cms/templates/aircox/cms/website.html @@ -16,7 +16,7 @@ {{ website.name }} {% if title %}- {{ title }} {% endif %} - {% block header %} + {% block page_header %} {% if menus.header %} {{ menus.header|safe }} {% endif %} @@ -32,30 +32,35 @@ {{ menus.left|safe }} {% endif %} + {% if messages %} + + {% endif %} +
{% endif %} - {% if messages %} - + {% block title %} + {% if title %} +

{{ title }}

{% endif %} + {% endblock %} - {% block pre_title %} - {% endblock %} -

- {% block title %} - {{ title }} - {% endblock %} -

- {% block post_title %} + {% block header %} + {% if header %} +
+ {{ header|safe }} +
+ {% endif %} {% endblock %} +
{% block content %} {% endblock %} diff --git a/cms/views.py b/cms/views.py index 62ee0da..dbd67dd 100644 --- a/cms/views.py +++ b/cms/views.py @@ -14,7 +14,13 @@ class PostBaseView: title = '' # title of the page embed = False # page is embed (if True, only post content is printed attrs = '' # attr for the HTML element of the content - css_classes = ''# css classes for the HTML element of the content + css_class = '' # css classes for the HTML element of the content + + def add_css_class(self, css_class): + if self.css_class: + self.css_class += ' ' + css_class + else: + self.css_class = css_class def get_base_context(self, **kwargs): """ @@ -58,12 +64,14 @@ class PostListView(PostBaseView, ListView): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + self.add_css_class('list') if not self.list: self.list = sections.List( truncate = 32, fields = [ 'date', 'time', 'image', 'title', 'content' ], ) + self.template_name = self.list.template_name def dispatch(self, request, *args, **kwargs): self.route = self.kwargs.get('route') or self.route @@ -95,11 +103,11 @@ class PostListView(PostBaseView, ListView): field for field in query.get('fields') if field in self.__class__.fields ] - return qs def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) + context = self.list.get_context(request = self.request, **self.kwargs) + context.update(super().get_context_data(**kwargs)) context.update(self.get_base_context(**kwargs)) if self.title: @@ -110,11 +118,11 @@ class PostListView(PostBaseView, ListView): **self.kwargs) context.update({ - 'title': title, - 'base_template': 'aircox/cms/website.html', - 'css_class': 'list' if not self.css_class else \ - 'list ' + self.css_class, - 'list': self.list, + 'title': title, + 'base_template': 'aircox/cms/website.html', + 'css_class': self.css_class + ' ' + context.get('css_class') + if self.css_class else context.get('css_class'), + 'list': self.list, }) # FIXME: list.url = if self.route: self.model(self.route, self.kwargs) else '' return context @@ -137,6 +145,7 @@ class PostDetailView(DetailView, PostBaseView): def __init__(self, sections = None, *args, **kwargs): super().__init__(*args, **kwargs) + self.add_css_class('detail') self.sections = sections or [] def get_queryset(self): @@ -159,11 +168,12 @@ class PostDetailView(DetailView, PostBaseView): kwargs['object'] = self.object context.update({ + 'title': self.object.title, 'content': ''.join([ section.get(request = self.request, **kwargs) for section in self.sections ]), - 'css_class': 'detail', + 'css_class': self.css_class, }) return context @@ -192,10 +202,8 @@ class PageView(TemplateView, PostBaseView): css_class = 'page' def __init__(self, *args, **kwargs): - css_class = 'css_class' in kwargs and kwargs.pop('css_class') - if css_class: - self.css_class += ' ' + css_class super().__init__(*args, **kwargs) + self.add_css_class('page') def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) diff --git a/website/sections.py b/website/sections.py index 09b9b90..7e78a70 100644 --- a/website/sections.py +++ b/website/sections.py @@ -115,80 +115,57 @@ class Playlist(sections.List): class Schedule(Diffusions): """ - Schedule printing diffusions starting at the given date - - * date: if set use this date instead of now; - * days: number of days to show; - * time_format: force format of the date in schedule header; + Render a list of diffusions in the form of a schedule """ + template_name = 'aircox/website/schedule.html' date = None days = 7 - time_format = '%a. %d' + nav_date_format = '%a. %d' + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.add_css_class('schedule') + + @staticmethod + def get_week_dates(date): + first = date - tz.timedelta(days=date.weekday()) + return [ first + tz.timedelta(days=i) for i in range(0, 7) ] + + def date_or_default(self): + if self.date: + return self.date + elif 'year' in self.kwargs: + return tz.datetime(year = int(self.kwargs['year']), + month = int(self.kwargs['month']), + day = int(self.kwargs['day']), + hour = 0, minute = 0, second = 0, + microsecond = 0) + return tz.datetime.now() def get_diffs(self): - date = self.date or tz.datetime.now() + date = self.date_or_default() return super().get_diffs( start__year = date.year, start__month = date.month, start__day = date.day, ) - @property - def header(self): - date = self.date or tz.datetime.now() - date.replace(hour = 0, minute = 0, second = 0, microsecond = 0) - curr = date - tz.timedelta(days=date.weekday()) - last = curr + tz.timedelta(days=7) - - r = """ - - """ - while curr < last: - r += \ - '{title}' \ - .format( - title = curr.strftime(self.time_format), - extra = ' class="selected"' if curr == date else '', - url = models.Diffusion.route_url( - routes.DateRoute, - year = curr.year, month = curr.month, day = curr.day, - ) - ) - curr += tz.timedelta(days=1) - return r + def get_context_data(self, **kwargs): + date = self.date_or_default() + dates_url = [ + (date, models.Diffusion.route_url( + routes.DateRoute, + year = date.year, month = date.month, day = date.day + )) + for date in self.get_week_dates(date) + ] + context = super().get_context_data(**kwargs) + context.update({ + 'date': date, + 'dates_url': dates_url, + }) + return context #class DatesOfDiffusion(sections.List):