fix bugs and rendering issues
This commit is contained in:
parent
19f7ceaf9f
commit
db54568a52
|
@ -57,12 +57,18 @@ class Section(View):
|
||||||
object = None
|
object = None
|
||||||
force_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):
|
def __init__ (self, *args, **kwargs):
|
||||||
super().__init__(*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:
|
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:
|
if not self.attrs:
|
||||||
self.attrs = {}
|
self.attrs = {}
|
||||||
|
@ -86,12 +92,14 @@ class Section(View):
|
||||||
'object': self.object,
|
'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.object = self.force_object or object
|
||||||
self.request = request
|
self.request = request
|
||||||
self.kwargs = kwargs
|
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:
|
if not context:
|
||||||
return ''
|
return ''
|
||||||
return render_to_string(self.template_name, context, request=request)
|
return render_to_string(self.template_name, context, request=request)
|
||||||
|
@ -201,7 +209,10 @@ class List(Section):
|
||||||
of ListItem.
|
of ListItem.
|
||||||
"""
|
"""
|
||||||
super().__init__(*args, **kwargs)
|
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:
|
if items:
|
||||||
self.object_list = [
|
self.object_list = [
|
||||||
ListItem(item) for item in items
|
ListItem(item) for item in items
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
{% extends "aircox/cms/website.html" %}
|
{% extends "aircox/cms/website.html" %}
|
||||||
{% load aircox_cms %}
|
{% load aircox_cms %}
|
||||||
|
|
||||||
{% block title %}
|
{% block header %}
|
||||||
{{ object.title }}
|
<header>
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block pre_title %}
|
|
||||||
<div class="pre_title meta">
|
|
||||||
{% if object.thread %}
|
{% if object.thread %}
|
||||||
<div class="threads">
|
<div class="threads">
|
||||||
{{ object|threads:' > '|safe }}
|
{{ object|threads:' > '|safe }}
|
||||||
|
@ -24,7 +20,7 @@
|
||||||
{{ object.tags.all|join:', ' }}
|
{{ object.tags.all|join:', ' }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</header>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
|
@ -6,18 +6,14 @@
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% if title %}
|
{% if title %}
|
||||||
<h1>
|
<h1>{{ title }}</h1>
|
||||||
{{ title }}
|
|
||||||
</h1>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
{% if header %}
|
|
||||||
<header>
|
<header>
|
||||||
{{ header|safe }}
|
{{ header|safe }}
|
||||||
</header>
|
</header>
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<title>{{ website.name }} {% if title %}- {{ title }} {% endif %}</title>
|
<title>{{ website.name }} {% if title %}- {{ title }} {% endif %}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% block header %}
|
{% block page_header %}
|
||||||
{% if menus.header %}
|
{% if menus.header %}
|
||||||
{{ menus.header|safe }}
|
{{ menus.header|safe }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -32,30 +32,35 @@
|
||||||
{{ menus.left|safe }}
|
{{ menus.left|safe }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if messages %}
|
||||||
|
<ul class="messages">
|
||||||
|
{% for message in messages %}
|
||||||
|
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>
|
||||||
|
{{ message }}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<main {% if css_class %} class="{{ css_class }}" {% endif %}
|
<main {% if css_class %} class="{{ css_class }}" {% endif %}
|
||||||
{% for k, v in attrs.items %}
|
{% for k, v in attrs.items %}
|
||||||
{{ k }} = "{{ v|addslashes }}"
|
{{ k }} = "{{ v|addslashes }}"
|
||||||
{% endfor %} >
|
{% endfor %} >
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if messages %}
|
{% block title %}
|
||||||
<ul class="messages">
|
{% if title %}
|
||||||
{% for message in messages %}
|
<h1>{{ title }}</h1>
|
||||||
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>
|
|
||||||
{{ message }}
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block pre_title %}
|
{% block header %}
|
||||||
{% endblock %}
|
{% if header %}
|
||||||
<h1>
|
<header>
|
||||||
{% block title %}
|
{{ header|safe }}
|
||||||
{{ title }}
|
</header>
|
||||||
{% endblock %}
|
{% endif %}
|
||||||
</h1>
|
|
||||||
{% block post_title %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
32
cms/views.py
32
cms/views.py
|
@ -14,7 +14,13 @@ class PostBaseView:
|
||||||
title = '' # title of the page
|
title = '' # title of the page
|
||||||
embed = False # page is embed (if True, only post content is printed
|
embed = False # page is embed (if True, only post content is printed
|
||||||
attrs = '' # attr for the HTML element of the content
|
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):
|
def get_base_context(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -58,12 +64,14 @@ class PostListView(PostBaseView, ListView):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
self.add_css_class('list')
|
||||||
|
|
||||||
if not self.list:
|
if not self.list:
|
||||||
self.list = sections.List(
|
self.list = sections.List(
|
||||||
truncate = 32,
|
truncate = 32,
|
||||||
fields = [ 'date', 'time', 'image', 'title', 'content' ],
|
fields = [ 'date', 'time', 'image', 'title', 'content' ],
|
||||||
)
|
)
|
||||||
|
self.template_name = self.list.template_name
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
self.route = self.kwargs.get('route') or self.route
|
self.route = self.kwargs.get('route') or self.route
|
||||||
|
@ -95,11 +103,11 @@ class PostListView(PostBaseView, ListView):
|
||||||
field for field in query.get('fields')
|
field for field in query.get('fields')
|
||||||
if field in self.__class__.fields
|
if field in self.__class__.fields
|
||||||
]
|
]
|
||||||
|
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
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))
|
context.update(self.get_base_context(**kwargs))
|
||||||
|
|
||||||
if self.title:
|
if self.title:
|
||||||
|
@ -110,11 +118,11 @@ class PostListView(PostBaseView, ListView):
|
||||||
**self.kwargs)
|
**self.kwargs)
|
||||||
|
|
||||||
context.update({
|
context.update({
|
||||||
'title': title,
|
'title': title,
|
||||||
'base_template': 'aircox/cms/website.html',
|
'base_template': 'aircox/cms/website.html',
|
||||||
'css_class': 'list' if not self.css_class else \
|
'css_class': self.css_class + ' ' + context.get('css_class')
|
||||||
'list ' + self.css_class,
|
if self.css_class else context.get('css_class'),
|
||||||
'list': self.list,
|
'list': self.list,
|
||||||
})
|
})
|
||||||
# FIXME: list.url = if self.route: self.model(self.route, self.kwargs) else ''
|
# FIXME: list.url = if self.route: self.model(self.route, self.kwargs) else ''
|
||||||
return context
|
return context
|
||||||
|
@ -137,6 +145,7 @@ class PostDetailView(DetailView, PostBaseView):
|
||||||
|
|
||||||
def __init__(self, sections = None, *args, **kwargs):
|
def __init__(self, sections = None, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
self.add_css_class('detail')
|
||||||
self.sections = sections or []
|
self.sections = sections or []
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
@ -159,11 +168,12 @@ class PostDetailView(DetailView, PostBaseView):
|
||||||
|
|
||||||
kwargs['object'] = self.object
|
kwargs['object'] = self.object
|
||||||
context.update({
|
context.update({
|
||||||
|
'title': self.object.title,
|
||||||
'content': ''.join([
|
'content': ''.join([
|
||||||
section.get(request = self.request, **kwargs)
|
section.get(request = self.request, **kwargs)
|
||||||
for section in self.sections
|
for section in self.sections
|
||||||
]),
|
]),
|
||||||
'css_class': 'detail',
|
'css_class': self.css_class,
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@ -192,10 +202,8 @@ class PageView(TemplateView, PostBaseView):
|
||||||
css_class = 'page'
|
css_class = 'page'
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
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)
|
super().__init__(*args, **kwargs)
|
||||||
|
self.add_css_class('page')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
|
@ -115,80 +115,57 @@ class Playlist(sections.List):
|
||||||
|
|
||||||
class Schedule(Diffusions):
|
class Schedule(Diffusions):
|
||||||
"""
|
"""
|
||||||
Schedule printing diffusions starting at the given date
|
Render a list of diffusions in the form of a schedule
|
||||||
|
|
||||||
* 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;
|
|
||||||
"""
|
"""
|
||||||
|
template_name = 'aircox/website/schedule.html'
|
||||||
date = None
|
date = None
|
||||||
days = 7
|
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):
|
def get_diffs(self):
|
||||||
date = self.date or tz.datetime.now()
|
date = self.date_or_default()
|
||||||
return super().get_diffs(
|
return super().get_diffs(
|
||||||
start__year = date.year,
|
start__year = date.year,
|
||||||
start__month = date.month,
|
start__month = date.month,
|
||||||
start__day = date.day,
|
start__day = date.day,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
def get_context_data(self, **kwargs):
|
||||||
def header(self):
|
date = self.date_or_default()
|
||||||
date = self.date or tz.datetime.now()
|
dates_url = [
|
||||||
date.replace(hour = 0, minute = 0, second = 0, microsecond = 0)
|
(date, models.Diffusion.route_url(
|
||||||
curr = date - tz.timedelta(days=date.weekday())
|
routes.DateRoute,
|
||||||
last = curr + tz.timedelta(days=7)
|
year = date.year, month = date.month, day = date.day
|
||||||
|
))
|
||||||
r = """
|
for date in self.get_week_dates(date)
|
||||||
<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(
|
|
||||||
routes.DateRoute,
|
|
||||||
year = curr.year, month = curr.month, day = curr.day,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
curr += tz.timedelta(days=1)
|
|
||||||
return r
|
|
||||||
|
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context.update({
|
||||||
|
'date': date,
|
||||||
|
'dates_url': dates_url,
|
||||||
|
})
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
#class DatesOfDiffusion(sections.List):
|
#class DatesOfDiffusion(sections.List):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user