forked from rc/aircox
work on schedule rendering; update comments views to be more coherent
This commit is contained in:
parent
db54568a52
commit
2365cc8b8e
|
@ -59,6 +59,7 @@ class Section(View):
|
|||
|
||||
def add_css_class(self, css_class):
|
||||
if self.css_class:
|
||||
if css_class not in self.css_class:
|
||||
self.css_class += ' ' + css_class
|
||||
else:
|
||||
self.css_class = css_class
|
||||
|
@ -240,6 +241,7 @@ class Comments(List):
|
|||
Section used to render comment form and comments list. It renders the
|
||||
form and comments, and save them.
|
||||
"""
|
||||
template_name = 'aircox/cms/comments.html'
|
||||
title=_('Comments')
|
||||
css_class='comments'
|
||||
truncate = 0
|
||||
|
@ -253,6 +255,8 @@ class Comments(List):
|
|||
'Please check errors below')
|
||||
|
||||
def get_object_list(self):
|
||||
if not self.object:
|
||||
return
|
||||
qs = self.object.get_comments().filter(published=True). \
|
||||
order_by('-date')
|
||||
return [ ListItem(post=comment, css_class="comment",
|
||||
|
@ -273,15 +277,14 @@ class Comments(List):
|
|||
return ''
|
||||
|
||||
def get_context_data(self):
|
||||
comment_form = None
|
||||
if self.object:
|
||||
post = self.object
|
||||
if hasattr(post, 'allow_comments') and post.allow_comments:
|
||||
comment_form = (self.comment_form or CommentForm())
|
||||
else:
|
||||
comment_form = None
|
||||
|
||||
context = super().get_context_data()
|
||||
context.update({
|
||||
'base_template': 'aircox/cms/comments.html',
|
||||
'comment_form': comment_form,
|
||||
})
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends "aircox/cms/section.html" %}
|
||||
{% extends 'aircox/cms/list.html' %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load honeypot %}
|
||||
|
|
48
cms/views.py
48
cms/views.py
|
@ -18,6 +18,7 @@ class PostBaseView:
|
|||
|
||||
def add_css_class(self, css_class):
|
||||
if self.css_class:
|
||||
if css_class not in self.css_class:
|
||||
self.css_class += ' ' + css_class
|
||||
else:
|
||||
self.css_class = css_class
|
||||
|
@ -47,6 +48,13 @@ class PostListView(PostBaseView, ListView):
|
|||
"""
|
||||
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:
|
||||
* embed: view is embedded, render only the list
|
||||
* exclude: exclude item of the given id
|
||||
|
@ -64,17 +72,15 @@ 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' ],
|
||||
)
|
||||
if self.list:
|
||||
self.template_name = self.list.template_name
|
||||
self.css_class = self.list.css_class
|
||||
self.add_css_class('list')
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.route = self.kwargs.get('route') or self.route
|
||||
if request.GET.get('embed'):
|
||||
self.embed = True
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_queryset(self):
|
||||
|
@ -82,6 +88,7 @@ class PostListView(PostBaseView, ListView):
|
|||
qs = self.route.get_queryset(self.model, self.request,
|
||||
**self.kwargs)
|
||||
else:
|
||||
# FIXME: should neven happen
|
||||
qs = self.queryset or self.model.objects.all()
|
||||
|
||||
qs = qs.filter(published = True)
|
||||
|
@ -89,14 +96,10 @@ class PostListView(PostBaseView, ListView):
|
|||
query = self.request.GET
|
||||
if query.get('exclude'):
|
||||
qs = qs.exclude(id = int(query['exclude']))
|
||||
|
||||
if query.get('embed'):
|
||||
self.embed = True
|
||||
|
||||
if query.get('order') == 'asc':
|
||||
qs.order_by('date', 'id')
|
||||
if query.get('order') == 'desc':
|
||||
qs = qs.order_by('-date', '-id')
|
||||
else:
|
||||
qs.order_by('-date', '-id')
|
||||
qs = qs.order_by('date', 'id')
|
||||
|
||||
if query.get('fields'):
|
||||
self.fields = [
|
||||
|
@ -106,7 +109,15 @@ class PostListView(PostBaseView, ListView):
|
|||
return qs
|
||||
|
||||
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(self.get_base_context(**kwargs))
|
||||
|
||||
|
@ -120,9 +131,8 @@ class PostListView(PostBaseView, ListView):
|
|||
context.update({
|
||||
'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,
|
||||
'css_class': self.css_class,
|
||||
'list': list,
|
||||
})
|
||||
# FIXME: list.url = if self.route: self.model(self.route, self.kwargs) else ''
|
||||
return context
|
||||
|
@ -199,11 +209,9 @@ class PageView(TemplateView, PostBaseView):
|
|||
template_name = 'aircox/cms/detail.html'
|
||||
|
||||
sections = []
|
||||
css_class = 'page'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.add_css_class('page')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
|
|
@ -16,6 +16,7 @@ class Diffusions(sections.List):
|
|||
"""
|
||||
next_count = 5
|
||||
prev_count = 5
|
||||
order_by = '-start'
|
||||
show_schedule = False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -32,6 +33,8 @@ class Diffusions(sections.List):
|
|||
qs = qs.filter(**filter_args).order_by('start')
|
||||
|
||||
r = []
|
||||
if not self.next_count and not self.prev_count:
|
||||
return qs
|
||||
if self.next_count:
|
||||
r += list(programs.Diffusion.get(next=True, queryset = qs)
|
||||
.order_by('-start')[:self.next_count])
|
||||
|
@ -118,9 +121,12 @@ class Schedule(Diffusions):
|
|||
Render a list of diffusions in the form of a schedule
|
||||
"""
|
||||
template_name = 'aircox/website/schedule.html'
|
||||
next_count = None
|
||||
prev_count = None
|
||||
date = None
|
||||
days = 7
|
||||
nav_date_format = '%a. %d'
|
||||
fields = [ 'time', 'image', 'title']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
@ -144,11 +150,12 @@ class Schedule(Diffusions):
|
|||
|
||||
def get_diffs(self):
|
||||
date = self.date_or_default()
|
||||
return super().get_diffs(
|
||||
diffs = super().get_diffs(
|
||||
start__year = date.year,
|
||||
start__month = date.month,
|
||||
start__day = date.day,
|
||||
)
|
||||
return diffs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
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