From 157914a0a1f6006721da77bd992ea605083533fd Mon Sep 17 00:00:00 2001 From: bkfox Date: Thu, 26 May 2016 21:45:11 +0200 Subject: [PATCH] clean up, merge the different kind of lists, merge BaseSection & Section --- cms/models.py | 1 - cms/templates/aircox/cms/comments.html | 33 +++++++ cms/templates/aircox/cms/content_object.html | 8 -- cms/templates/aircox/cms/list.html | 86 ++++++++++++------- cms/templates/aircox/cms/menu.html | 10 --- cms/templates/aircox/cms/section.html | 53 ++++++------ .../aircox/cms/section_comments.html | 52 ----------- cms/templates/aircox/cms/section_list.html | 28 ------ cms/views.py | 47 +++++----- .../management/commands/diffusions_monitor.py | 1 - 10 files changed, 140 insertions(+), 179 deletions(-) create mode 100644 cms/templates/aircox/cms/comments.html delete mode 100644 cms/templates/aircox/cms/content_object.html delete mode 100644 cms/templates/aircox/cms/menu.html delete mode 100644 cms/templates/aircox/cms/section_comments.html delete mode 100644 cms/templates/aircox/cms/section_list.html diff --git a/cms/models.py b/cms/models.py index 54cf854..c068de2 100644 --- a/cms/models.py +++ b/cms/models.py @@ -170,7 +170,6 @@ class Post (models.Model): return self.route_url(routes.DetailRoute, { 'pk': self.pk, 'slug': slugify(self.title) }) - def get_object_list(self, request, object, **kwargs): type = ContentType.objects.get_for_model(object) qs = Comment.objects.filter( diff --git a/cms/templates/aircox/cms/comments.html b/cms/templates/aircox/cms/comments.html new file mode 100644 index 0000000..730adec --- /dev/null +++ b/cms/templates/aircox/cms/comments.html @@ -0,0 +1,33 @@ +{% extends "aircox/cms/section.html" %} + +{% load i18n %} +{% load honeypot %} + +{% block header %} +{% if comment_form %} +{% with comment_form as form %} +{{ form.non_field_errors }} +
+{% csrf_token %} +{% render_honeypot_field "hp_website" %} +
+ {{ form.author.errors }} + {{ form.author }} + +
+ {{ form.email.errors }} + {{ form.email }} + {{ form.url.errors }} + {{ form.url }} +
+
+
+ {{ form.content.errors }} + {{ form.content }} + +
+
+{% endwith %} +{% endif %} +{% endblock %} + diff --git a/cms/templates/aircox/cms/content_object.html b/cms/templates/aircox/cms/content_object.html deleted file mode 100644 index 5353c9c..0000000 --- a/cms/templates/aircox/cms/content_object.html +++ /dev/null @@ -1,8 +0,0 @@ - -<{{ tag }} class="{{ classes }}" - {% for k, v in attrs.items %}{{ k }} = "{{ v|addslashes }}" {% endfor %} > - {% block content %} - {{ content|safe }} - {% endblock %} - - diff --git a/cms/templates/aircox/cms/list.html b/cms/templates/aircox/cms/list.html index 9786b7b..7afebce 100644 --- a/cms/templates/aircox/cms/list.html +++ b/cms/templates/aircox/cms/list.html @@ -1,53 +1,78 @@ -{% extends "aircox/cms/website.html" %} +{% extends base_template %} {% load i18n %} {% load thumbnail %} + {% block content %} -
-{% for post in object_list %} - - {% if 'date' in view.fields or 'time' in view.fields %} - +{% if page_obj or list.url %} +{% endif %} {% endblock %} diff --git a/cms/templates/aircox/cms/menu.html b/cms/templates/aircox/cms/menu.html deleted file mode 100644 index acfc3f0..0000000 --- a/cms/templates/aircox/cms/menu.html +++ /dev/null @@ -1,10 +0,0 @@ - -<{{ tag }} class="menu menu_{{ position }} {{ classes }}" {% if name %} - name="{{ name }}" - id="{{ name }}" - {% endif %}> - {% for section in sections %} - {{ section|safe }} - {% endfor %} - - diff --git a/cms/templates/aircox/cms/section.html b/cms/templates/aircox/cms/section.html index 672ef50..59e3b78 100644 --- a/cms/templates/aircox/cms/section.html +++ b/cms/templates/aircox/cms/section.html @@ -1,34 +1,35 @@ -{% extends "aircox/cms/content_object.html" %} -{% block content %} +<{{ tag }} class="{{ css_class }}" + {% for k, v in list.attrs.items %} + {{ k }} = "{{ v|addslashes }}" + {% endfor %} > + +{% block title %} {% if title %}

- {% block section_title %} {{ title }} - {% endblock %}

{% endif %} - -{% if header %} -
- {% block section_header %} - {{ header }} - {% endblock %} -
-{% endif %} - -
- {% block section_content %} - {{ content|safe }} - {% endblock %} -
- -{% if footer %} -
- {% block section_footer %} - {{ footer }} - {% endblock %} -
-{% endif %} {% endblock %} +{% block header %} +{% if header %} +
+ {{ header }} +
+{% endif %} +{% endblock %} + +{% block content %} +{{ content|safe }} +{% endblock %} + +{% block footer %} +{% if footer %} +
+ {{ footer }} +
+{% endif %} +{% endblock %} + + diff --git a/cms/templates/aircox/cms/section_comments.html b/cms/templates/aircox/cms/section_comments.html deleted file mode 100644 index c05edca..0000000 --- a/cms/templates/aircox/cms/section_comments.html +++ /dev/null @@ -1,52 +0,0 @@ -{% extends "aircox/cms/section.html" %} - -{% load i18n %} -{% load honeypot %} - -{% block section_content %} -{{ form.non_field_errors }} -
-{% csrf_token %} -{% render_honeypot_field "hp_website" %} -
- {{ form.author.errors }} - {{ form.author }} - -
- {{ form.email.errors }} - {{ form.email }} - {{ form.url.errors }} - {{ form.url }} -
-
-
- {{ form.content.errors }} - {{ form.content }} - -
-
-
- {% for item in object_list %} -
- {{ item.content }} - - -
- {% endfor %} -
- -{% endblock %} - - diff --git a/cms/templates/aircox/cms/section_list.html b/cms/templates/aircox/cms/section_list.html deleted file mode 100644 index c28de59..0000000 --- a/cms/templates/aircox/cms/section_list.html +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "aircox/cms/section.html" %} - -{% load thumbnail %} - -{% block section_content %} - -{% endblock %} - diff --git a/cms/views.py b/cms/views.py index 95c1c20..ccf92f2 100644 --- a/cms/views.py +++ b/cms/views.py @@ -5,7 +5,10 @@ from django.views.generic.base import View from django.utils.translation import ugettext as _, ugettext_lazy from django.http import Http404 -from django.views.decorators.http import require_http_methods +from honeypot.decorators import verify_honeypot_value + +from aircox.cms.forms import CommentForm + class PostBaseView: website = None # corresponding website @@ -25,8 +28,9 @@ class PostBaseView: } if not self.embed: + object = self.object if hasattr(self, 'object') else None context['menus'] = { - k: v.get(self.request, object = self.object, **kwargs) + k: v.get(self.request, object = object, **kwargs) for k, v in { k: self.website.get_menu(k) for k in self.website.menu_layouts @@ -53,8 +57,7 @@ class PostListView(PostBaseView, ListView): model = None route = None - fields = [ 'date', 'time', 'image', 'title', 'content' ] - icon_size = '64x64' + list = None def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -93,28 +96,28 @@ class PostListView(PostBaseView, ListView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update(self.get_base_context(**kwargs)) - context.update({ - 'title': self.get_title(), - }) + + title = self.title if self.title else \ + self.route and self.route.get_title(self.model, self.request, + **self.kwargs) + context['title'] = title + context['base_template'] = 'aircox/cms/website.html' + + if not self.list: + import aircox.cms.sections as sections + self.list = sections.List( + truncate = 64, + fields = [ 'date', 'time', 'image', 'title', 'content' ], + ) + + context['list'] = self.list + # FIXME: list.url = if self.route: self.model(self.route, self.kwargs) else '' return context - def get_title(self): - if self.title: - return self.title - - title = self.route and self.route.get_title(self.model, self.request, - **self.kwargs) - return title - def get_url(self): - if self.route: - return self.model(self.route, self.kwargs) return '' -from honeypot.decorators import verify_honeypot_value -from aircox.cms.forms import CommentForm - class PostDetailView(DetailView, PostBaseView): """ Detail view for posts and children @@ -173,9 +176,8 @@ class PostDetailView(DetailView, PostBaseView): return self.get(request, *args, **kwargs) - class Menu(View): - template_name = 'aircox/cms/content_object.html' + template_name = 'aircox/cms/section.html' tag = 'nav' classes = '' attrs = '' @@ -212,4 +214,3 @@ class Menu(View): return render_to_string(self.template_name, context) - diff --git a/programs/management/commands/diffusions_monitor.py b/programs/management/commands/diffusions_monitor.py index 033dee7..794563d 100644 --- a/programs/management/commands/diffusions_monitor.py +++ b/programs/management/commands/diffusions_monitor.py @@ -74,7 +74,6 @@ class Actions: if manual: Diffusion.objects.bulk_create(items) else: - print('items: ', len(items)) for item in items: count[1] += cl.__check_conflicts(item, saved_items) if hasattr(item, 'do_not_save'):