fix bugs and rendering issues
This commit is contained in:
parent
19f7ceaf9f
commit
db54568a52
|
@ -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
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
{% extends "aircox/cms/website.html" %}
|
||||
{% load aircox_cms %}
|
||||
|
||||
{% block title %}
|
||||
{{ object.title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block pre_title %}
|
||||
<div class="pre_title meta">
|
||||
{% block header %}
|
||||
<header>
|
||||
{% if object.thread %}
|
||||
<div class="threads">
|
||||
{{ object|threads:' > '|safe }}
|
||||
|
@ -24,7 +20,7 @@
|
|||
{{ object.tags.all|join:', ' }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</header>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
|
@ -6,18 +6,14 @@
|
|||
|
||||
{% block title %}
|
||||
{% if title %}
|
||||
<h1>
|
||||
{{ title }}
|
||||
</h1>
|
||||
<h1>{{ title }}</h1>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block header %}
|
||||
{% if header %}
|
||||
<header>
|
||||
{{ header|safe }}
|
||||
</header>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<title>{{ website.name }} {% if title %}- {{ title }} {% endif %}</title>
|
||||
</head>
|
||||
<body>
|
||||
{% block header %}
|
||||
{% block page_header %}
|
||||
{% if menus.header %}
|
||||
{{ menus.header|safe }}
|
||||
{% endif %}
|
||||
|
@ -32,11 +32,6 @@
|
|||
{{ menus.left|safe }}
|
||||
{% endif %}
|
||||
|
||||
<main {% if css_class %} class="{{ css_class }}" {% endif %}
|
||||
{% for k, v in attrs.items %}
|
||||
{{ k }} = "{{ v|addslashes }}"
|
||||
{% endfor %} >
|
||||
{% endif %}
|
||||
{% if messages %}
|
||||
<ul class="messages">
|
||||
{% for message in messages %}
|
||||
|
@ -47,15 +42,25 @@
|
|||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{% block pre_title %}
|
||||
{% endblock %}
|
||||
<h1>
|
||||
<main {% if css_class %} class="{{ css_class }}" {% endif %}
|
||||
{% for k, v in attrs.items %}
|
||||
{{ k }} = "{{ v|addslashes }}"
|
||||
{% endfor %} >
|
||||
{% endif %}
|
||||
{% block title %}
|
||||
{{ title }}
|
||||
{% if title %}
|
||||
<h1>{{ title }}</h1>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
</h1>
|
||||
{% block post_title %}
|
||||
|
||||
{% block header %}
|
||||
{% if header %}
|
||||
<header>
|
||||
{{ header|safe }}
|
||||
</header>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
<div class="content">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
|
|
26
cms/views.py
26
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:
|
||||
|
@ -112,8 +120,8 @@ class PostListView(PostBaseView, ListView):
|
|||
context.update({
|
||||
'title': title,
|
||||
'base_template': 'aircox/cms/website.html',
|
||||
'css_class': 'list' if not self.css_class else \
|
||||
'list ' + self.css_class,
|
||||
'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 ''
|
||||
|
@ -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)
|
||||
|
|
|
@ -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 = """
|
||||
<script>function update_schedule(url, event) {
|
||||
var target = event.currentTarget;
|
||||
|
||||
while(target && target.className.indexOf('section'))
|
||||
target = target.parentNode;
|
||||
|
||||
if(!target)
|
||||
return false;
|
||||
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if(xhr.readyState != 4 || xhr.status != 200 && xhr.status)
|
||||
return;
|
||||
|
||||
var obj = document.createElement('div');
|
||||
obj.innerHTML = xhr.responseText;
|
||||
obj = obj.getElementsByTagName('ul');
|
||||
console.log(obj)
|
||||
if(!obj)
|
||||
return;
|
||||
|
||||
obj = obj[0];
|
||||
target.replaceChild(obj, target.querySelector('ul'))
|
||||
target.querySelector('nav a').href = url
|
||||
}
|
||||
|
||||
xhr.open('GET', url + '?embed=1', true);
|
||||
xhr.send();
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
"""
|
||||
while curr < last:
|
||||
r += \
|
||||
'<a href="{url}"{extra} '\
|
||||
'onclick="return update_schedule(\'{url}\', event)">{title}</a>' \
|
||||
.format(
|
||||
title = curr.strftime(self.time_format),
|
||||
extra = ' class="selected"' if curr == date else '',
|
||||
url = models.Diffusion.route_url(
|
||||
def get_context_data(self, **kwargs):
|
||||
date = self.date_or_default()
|
||||
dates_url = [
|
||||
(date, models.Diffusion.route_url(
|
||||
routes.DateRoute,
|
||||
year = curr.year, month = curr.month, day = curr.day,
|
||||
)
|
||||
)
|
||||
curr += tz.timedelta(days=1)
|
||||
return r
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user