From 474a33cfa5575d7cb28464cd6ba4a92b8ed5645b Mon Sep 17 00:00:00 2001 From: bkfox Date: Tue, 13 Oct 2015 17:52:59 +0200 Subject: [PATCH] work on lists --- aircox_cms/routes.py | 8 +++-- aircox_cms/templates/aircox_cms/list.html | 25 ++++++++++++-- aircox_cms/templates/aircox_cms/section.html | 12 +++---- aircox_cms/utils.py | 21 ++++++++++++ aircox_cms/views.py | 34 +++++++++++++------- aircox_cms/website.py | 5 +++ website/static/website/styles.css | 17 +++++++--- website/urls.py | 1 + website/views.py | 9 ++++-- 9 files changed, 105 insertions(+), 27 deletions(-) create mode 100644 aircox_cms/utils.py diff --git a/aircox_cms/routes.py b/aircox_cms/routes.py index 82467ab..8825bde 100644 --- a/aircox_cms/routes.py +++ b/aircox_cms/routes.py @@ -56,6 +56,10 @@ class Route: def get_title (cl, model, request, **kwargs): return '' + @classmethod + def get_view_name (cl, name): + return name + '_' + cl.name + @classmethod def as_url (cl, name, model, view, view_kwargs = None): pattern = '^{}/{}'.format(name, cl.name) @@ -77,7 +81,7 @@ class Route: kwargs.update(view_kwargs) return url(pattern, view, kwargs = kwargs, - name = name + '_' + cl.name) + name = cl.get_view_name(name)) class DetailRoute (Route): @@ -123,7 +127,7 @@ class ThreadRoute (Route): @classmethod def get_queryset (cl, website, model, request, thread_model, pk, **kwargs): if type(thread_model) is str: - thread_model = website.registry.get(thread_model).model + thread_model = website.registry.get(thread_model) if not thread_model: return diff --git a/aircox_cms/templates/aircox_cms/list.html b/aircox_cms/templates/aircox_cms/list.html index 072c5c2..1edd77d 100644 --- a/aircox_cms/templates/aircox_cms/list.html +++ b/aircox_cms/templates/aircox_cms/list.html @@ -4,7 +4,7 @@ {% load thumbnail %} {% block content %} -
+
{% for post in object_list %} @@ -39,6 +39,27 @@ {% endfor %}
+ + {% endblock %} - diff --git a/aircox_cms/templates/aircox_cms/section.html b/aircox_cms/templates/aircox_cms/section.html index 3f549a4..25febd0 100644 --- a/aircox_cms/templates/aircox_cms/section.html +++ b/aircox_cms/templates/aircox_cms/section.html @@ -23,12 +23,12 @@ {% endblock %}
-{% if bottom %} -
- {% block section_bottom %} - {{ bottom }} +{% if footer %} +
+ {% block section_footer %} + {{ footer }} {% endblock %} -
+ {% endif %} -{% endblock %} +{% endblock %} diff --git a/aircox_cms/utils.py b/aircox_cms/utils.py new file mode 100644 index 0000000..8f25573 --- /dev/null +++ b/aircox_cms/utils.py @@ -0,0 +1,21 @@ +from django.contrib.contenttypes.models import ContentType +from django.core.urlresolvers import reverse + + +def get_url (website, route, model, kwargs): + name = website.name_of_model(model) + if not name: + return + name = route.get_view_name(name) + return reverse(name, kwargs = kwargs) + + +def filter_thread (qs, object): + model_type = ContentType.objects.get_for_model(object.__class__) + return qs.filter( + thread_pk = object.pk, + thread_type__pk = model_type.pk + ) + + + diff --git a/aircox_cms/views.py b/aircox_cms/views.py index 8a3cead..8bb357d 100644 --- a/aircox_cms/views.py +++ b/aircox_cms/views.py @@ -5,11 +5,13 @@ from django.shortcuts import render from django.template.loader import render_to_string from django.views.generic import ListView, DetailView from django.views.generic.base import View, TemplateResponseMixin +from django.core.paginator import Paginator from django.core import serializers from django.utils.translation import ugettext as _, ugettext_lazy from django.utils.html import escape import aircox_cms.routes as routes +import aircox_cms.utils as utils class PostBaseView: @@ -31,7 +33,7 @@ class PostBaseView: if not self.embed: context['menus'] = { - k: v.get(self.request, **kwargs) + k: v.get(self.request, website = self.website, **kwargs) for k, v in { k: self.website.get_menu(k) for k in self.website.menu_layouts @@ -55,6 +57,7 @@ class PostListView (PostBaseView, ListView): order = 'desc' reverse = False fields = None + page = 1 def __init__ (self, query): if query: @@ -69,6 +72,7 @@ class PostListView (PostBaseView, ListView): template_name = 'aircox_cms/list.html' allow_empty = True + paginate_by = 50 model = None route = None @@ -128,6 +132,12 @@ class PostListView (PostBaseView, ListView): **self.kwargs) return title + def get_url (self): + if self.route: + return utils.get_urls(self.website, self.route, + self.model, self.kwargs) + return '' + class PostDetailView (DetailView, PostBaseView): """ @@ -161,7 +171,7 @@ class PostDetailView (DetailView, PostBaseView): context.update(self.get_base_context()) context.update({ 'sections': [ - section.get(self.request, **kwargs) + section.get(self.request, website = self.website, **kwargs) for section in self.sections ] }) @@ -189,13 +199,15 @@ class Menu (View): 'classes': self.classes, 'position': self.position, 'sections': [ - section.get(self.request, object = None, **kwargs) + section.get(self.request, website = self.website, + object = None, **kwargs) for section in self.sections ] } - def get (self, request, **kwargs): + def get (self, request, website, **kwargs): self.request = request + self.website = website context = self.get_context_data(**kwargs) return render_to_string(self.template_name, context) @@ -225,8 +237,9 @@ class BaseSection (View): 'content': self.content, } - def get (self, request, **kwargs): + def get (self, request, website, **kwargs): self.request = request + self.website = website self.kwargs = kwargs context = self.get_context_data() @@ -245,14 +258,14 @@ class Section (BaseSection): object_required = False title = '' header = '' - bottom = '' + footer = '' def get_context_data (self): context = super().get_context_data() context.update({ 'title': self.title, 'header': self.header, - 'bottom': self.bottom, + 'footer': self.footer, }) return context @@ -277,7 +290,6 @@ class Sections: static(self.url), ) - class PostContent (Section): """ Render the content of the Post (format the text a bit and escape HTML @@ -290,7 +302,6 @@ class Sections: content = re.sub(r'\n', r'
', content) return content - class PostImage (Section): """ Render the image of the Post @@ -301,7 +312,6 @@ class Sections: self.object.image.url ) - class List (Section): """ Section to render list. The context item 'object_list' is used as list of @@ -342,7 +352,6 @@ class Sections: }) return context - class Urls (List): """ Render a list of urls of targets that are Posts @@ -369,6 +378,9 @@ class Sections: icon_size = '64x64' fields = [ 'date', 'time', 'image', 'title', 'content' ] + def get_url (self): + return '' + def get_object_list (self): return [] diff --git a/aircox_cms/website.py b/aircox_cms/website.py index db53ffb..b83c8d0 100644 --- a/aircox_cms/website.py +++ b/aircox_cms/website.py @@ -21,6 +21,11 @@ class Website: self.urls = [] self.__dict__.update(kwargs) + def name_of_model (self, model): + for name, _model in self.registry.items(): + if model is _model: + return name + def register_model (self, name, model): """ Register a model and return the name under which it is registered. diff --git a/website/static/website/styles.css b/website/static/website/styles.css index 653dd25..015545c 100644 --- a/website/static/website/styles.css +++ b/website/static/website/styles.css @@ -81,8 +81,8 @@ a:hover { } .page { - width: 100%; - padding: 1.5em 0em; + width: calc(100% - 0.4em); + padding: 1.5em 0.2em; background-color: rgba(255, 255, 255, 0.8); } @@ -92,11 +92,20 @@ a:hover { } -main .post_list { - background-color: #F2F2F2; +.post_list { + padding: 0.1em; border: 1px #818181 dotted; } + .post_list.embed + nav { + text-align: right; + } + + .post_list:not(.embed) + nav { + text-align: center; + } + + main .post_list .post_item { min-height: 64px; padding: 0.2em; diff --git a/website/urls.py b/website/urls.py index 8022237..e64a17e 100644 --- a/website/urls.py +++ b/website/urls.py @@ -72,6 +72,7 @@ website.register ( 'episode', Episode, sections = base_sections, + routes = base_routes, ) urlpatterns = website.urls diff --git a/website/views.py b/website/views.py index e10eb1c..96dfa40 100644 --- a/website/views.py +++ b/website/views.py @@ -7,6 +7,8 @@ from django.utils import timezone as tz from django.utils.translation import ugettext as _, ugettext_lazy import aircox_programs.models as programs +import aircox_cms.routes as routes +import aircox_cms.utils as utils from aircox_cms.views import Sections from website.models import * @@ -39,7 +41,11 @@ class EpisodesSection (Sections.Posts): title = _('Episodes') def get_object_list (self): - return Episode.objects.filter(related__program = self.object.related.pk) + return utils.filter_thread(Episode.objects, self.object) + + def get_url (self): + return utils.get_url(self.website, routes.ThreadRoute, Episode, + { 'thread_model': 'program', 'pk': self.object.pk}) class PreviousDiffusions (Sections.Posts): title = _('Previous Diffusions') @@ -65,4 +71,3 @@ class PreviousDiffusions (Sections.Posts): return episodes -