work on schedule rendering; update comments views to be more coherent
This commit is contained in:
parent
db54568a52
commit
2365cc8b8e
|
@ -59,7 +59,8 @@ class Section(View):
|
||||||
|
|
||||||
def add_css_class(self, css_class):
|
def add_css_class(self, css_class):
|
||||||
if self.css_class:
|
if self.css_class:
|
||||||
self.css_class += ' ' + css_class
|
if css_class not in self.css_class:
|
||||||
|
self.css_class += ' ' + css_class
|
||||||
else:
|
else:
|
||||||
self.css_class = css_class
|
self.css_class = css_class
|
||||||
|
|
||||||
|
@ -240,6 +241,7 @@ class Comments(List):
|
||||||
Section used to render comment form and comments list. It renders the
|
Section used to render comment form and comments list. It renders the
|
||||||
form and comments, and save them.
|
form and comments, and save them.
|
||||||
"""
|
"""
|
||||||
|
template_name = 'aircox/cms/comments.html'
|
||||||
title=_('Comments')
|
title=_('Comments')
|
||||||
css_class='comments'
|
css_class='comments'
|
||||||
truncate = 0
|
truncate = 0
|
||||||
|
@ -253,6 +255,8 @@ class Comments(List):
|
||||||
'Please check errors below')
|
'Please check errors below')
|
||||||
|
|
||||||
def get_object_list(self):
|
def get_object_list(self):
|
||||||
|
if not self.object:
|
||||||
|
return
|
||||||
qs = self.object.get_comments().filter(published=True). \
|
qs = self.object.get_comments().filter(published=True). \
|
||||||
order_by('-date')
|
order_by('-date')
|
||||||
return [ ListItem(post=comment, css_class="comment",
|
return [ ListItem(post=comment, css_class="comment",
|
||||||
|
@ -273,15 +277,14 @@ class Comments(List):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def get_context_data(self):
|
def get_context_data(self):
|
||||||
post = self.object
|
comment_form = None
|
||||||
if hasattr(post, 'allow_comments') and post.allow_comments:
|
if self.object:
|
||||||
comment_form = (self.comment_form or CommentForm())
|
post = self.object
|
||||||
else:
|
if hasattr(post, 'allow_comments') and post.allow_comments:
|
||||||
comment_form = None
|
comment_form = (self.comment_form or CommentForm())
|
||||||
|
|
||||||
context = super().get_context_data()
|
context = super().get_context_data()
|
||||||
context.update({
|
context.update({
|
||||||
'base_template': 'aircox/cms/comments.html',
|
|
||||||
'comment_form': comment_form,
|
'comment_form': comment_form,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% extends "aircox/cms/section.html" %}
|
{% extends 'aircox/cms/list.html' %}
|
||||||
|
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load honeypot %}
|
{% load honeypot %}
|
||||||
|
|
50
cms/views.py
50
cms/views.py
|
@ -18,7 +18,8 @@ class PostBaseView:
|
||||||
|
|
||||||
def add_css_class(self, css_class):
|
def add_css_class(self, css_class):
|
||||||
if self.css_class:
|
if self.css_class:
|
||||||
self.css_class += ' ' + css_class
|
if css_class not in self.css_class:
|
||||||
|
self.css_class += ' ' + css_class
|
||||||
else:
|
else:
|
||||||
self.css_class = css_class
|
self.css_class = css_class
|
||||||
|
|
||||||
|
@ -47,6 +48,13 @@ class PostListView(PostBaseView, ListView):
|
||||||
"""
|
"""
|
||||||
List view for posts and children.
|
List view for posts and children.
|
||||||
|
|
||||||
|
If list is given:
|
||||||
|
- use list's template and css_class
|
||||||
|
- use list's context as base context
|
||||||
|
|
||||||
|
Note that we never use list.get_object_list, but instead use
|
||||||
|
route.get_queryset or self.model.objects.all()
|
||||||
|
|
||||||
Request.GET params:
|
Request.GET params:
|
||||||
* embed: view is embedded, render only the list
|
* embed: view is embedded, render only the list
|
||||||
* exclude: exclude item of the given id
|
* exclude: exclude item of the given id
|
||||||
|
@ -64,17 +72,15 @@ class PostListView(PostBaseView, ListView):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
if self.list:
|
||||||
|
self.template_name = self.list.template_name
|
||||||
|
self.css_class = self.list.css_class
|
||||||
self.add_css_class('list')
|
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):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
self.route = self.kwargs.get('route') or self.route
|
self.route = self.kwargs.get('route') or self.route
|
||||||
|
if request.GET.get('embed'):
|
||||||
|
self.embed = True
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
@ -82,6 +88,7 @@ class PostListView(PostBaseView, ListView):
|
||||||
qs = self.route.get_queryset(self.model, self.request,
|
qs = self.route.get_queryset(self.model, self.request,
|
||||||
**self.kwargs)
|
**self.kwargs)
|
||||||
else:
|
else:
|
||||||
|
# FIXME: should neven happen
|
||||||
qs = self.queryset or self.model.objects.all()
|
qs = self.queryset or self.model.objects.all()
|
||||||
|
|
||||||
qs = qs.filter(published = True)
|
qs = qs.filter(published = True)
|
||||||
|
@ -89,14 +96,10 @@ class PostListView(PostBaseView, ListView):
|
||||||
query = self.request.GET
|
query = self.request.GET
|
||||||
if query.get('exclude'):
|
if query.get('exclude'):
|
||||||
qs = qs.exclude(id = int(query['exclude']))
|
qs = qs.exclude(id = int(query['exclude']))
|
||||||
|
if query.get('order') == 'desc':
|
||||||
if query.get('embed'):
|
qs = qs.order_by('-date', '-id')
|
||||||
self.embed = True
|
|
||||||
|
|
||||||
if query.get('order') == 'asc':
|
|
||||||
qs.order_by('date', 'id')
|
|
||||||
else:
|
else:
|
||||||
qs.order_by('-date', '-id')
|
qs = qs.order_by('date', 'id')
|
||||||
|
|
||||||
if query.get('fields'):
|
if query.get('fields'):
|
||||||
self.fields = [
|
self.fields = [
|
||||||
|
@ -106,7 +109,15 @@ class PostListView(PostBaseView, ListView):
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = self.list.get_context(request = self.request, **self.kwargs)
|
if self.list:
|
||||||
|
list = self.list
|
||||||
|
else:
|
||||||
|
list = sections.List(
|
||||||
|
truncate = 32,
|
||||||
|
fields = [ 'date', 'time', 'image', 'title', 'content' ],
|
||||||
|
)
|
||||||
|
|
||||||
|
context = list.get_context(request = self.request, **self.kwargs) or {}
|
||||||
context.update(super().get_context_data(**kwargs))
|
context.update(super().get_context_data(**kwargs))
|
||||||
context.update(self.get_base_context(**kwargs))
|
context.update(self.get_base_context(**kwargs))
|
||||||
|
|
||||||
|
@ -120,9 +131,8 @@ class PostListView(PostBaseView, ListView):
|
||||||
context.update({
|
context.update({
|
||||||
'title': title,
|
'title': title,
|
||||||
'base_template': 'aircox/cms/website.html',
|
'base_template': 'aircox/cms/website.html',
|
||||||
'css_class': self.css_class + ' ' + context.get('css_class')
|
'css_class': self.css_class,
|
||||||
if self.css_class else context.get('css_class'),
|
'list': 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
|
||||||
|
@ -199,11 +209,9 @@ class PageView(TemplateView, PostBaseView):
|
||||||
template_name = 'aircox/cms/detail.html'
|
template_name = 'aircox/cms/detail.html'
|
||||||
|
|
||||||
sections = []
|
sections = []
|
||||||
css_class = 'page'
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
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)
|
||||||
|
|
|
@ -16,6 +16,7 @@ class Diffusions(sections.List):
|
||||||
"""
|
"""
|
||||||
next_count = 5
|
next_count = 5
|
||||||
prev_count = 5
|
prev_count = 5
|
||||||
|
order_by = '-start'
|
||||||
show_schedule = False
|
show_schedule = False
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -32,6 +33,8 @@ class Diffusions(sections.List):
|
||||||
qs = qs.filter(**filter_args).order_by('start')
|
qs = qs.filter(**filter_args).order_by('start')
|
||||||
|
|
||||||
r = []
|
r = []
|
||||||
|
if not self.next_count and not self.prev_count:
|
||||||
|
return qs
|
||||||
if self.next_count:
|
if self.next_count:
|
||||||
r += list(programs.Diffusion.get(next=True, queryset = qs)
|
r += list(programs.Diffusion.get(next=True, queryset = qs)
|
||||||
.order_by('-start')[:self.next_count])
|
.order_by('-start')[:self.next_count])
|
||||||
|
@ -118,9 +121,12 @@ class Schedule(Diffusions):
|
||||||
Render a list of diffusions in the form of a schedule
|
Render a list of diffusions in the form of a schedule
|
||||||
"""
|
"""
|
||||||
template_name = 'aircox/website/schedule.html'
|
template_name = 'aircox/website/schedule.html'
|
||||||
|
next_count = None
|
||||||
|
prev_count = None
|
||||||
date = None
|
date = None
|
||||||
days = 7
|
days = 7
|
||||||
nav_date_format = '%a. %d'
|
nav_date_format = '%a. %d'
|
||||||
|
fields = [ 'time', 'image', 'title']
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
@ -144,11 +150,12 @@ class Schedule(Diffusions):
|
||||||
|
|
||||||
def get_diffs(self):
|
def get_diffs(self):
|
||||||
date = self.date_or_default()
|
date = self.date_or_default()
|
||||||
return super().get_diffs(
|
diffs = 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,
|
||||||
)
|
)
|
||||||
|
return diffs
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
date = self.date_or_default()
|
date = self.date_or_default()
|
||||||
|
|
47
website/templates/aircox/website/schedule.html
Normal file
47
website/templates/aircox/website/schedule.html
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
{% extends 'aircox/cms/list.html' %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<header>
|
||||||
|
<script>
|
||||||
|
function update_schedule(event) {
|
||||||
|
var target = event.currentTarget;
|
||||||
|
var url = target.getAttribute('href');
|
||||||
|
|
||||||
|
var schedule = target;
|
||||||
|
while(schedule && schedule.className.indexOf('schedule'))
|
||||||
|
schedule = schedule.parentNode;
|
||||||
|
if(!schedule)
|
||||||
|
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;
|
||||||
|
target.replaceChild(
|
||||||
|
obj.querySelector('.content'),
|
||||||
|
schedule.querySelector('.schedule .content')
|
||||||
|
)
|
||||||
|
target.replaceChild(
|
||||||
|
obj.querySelector('.schedule header'),
|
||||||
|
schedule.querySelector('.schedule header')
|
||||||
|
)
|
||||||
|
// target.querySelector('nav a').href = url
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.open('GET', url + '?embed=1', true);
|
||||||
|
xhr.send();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{% for curr, url in dates_url %}
|
||||||
|
<a href="{{ url }}" onclick="return update_schedule(event);" {% if curr == date %}
|
||||||
|
class="selected"{% endif %}>
|
||||||
|
{{ curr|date:'D. d' }}
|
||||||
|
</a>
|
||||||
|
{% endfor %}
|
||||||
|
</header>
|
||||||
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user