From e0a268505e5976004e7f9a34c544abbed648f8f1 Mon Sep 17 00:00:00 2001 From: bkfox Date: Mon, 30 May 2016 13:23:46 +0200 Subject: [PATCH] work on pagination --- cms/models.py | 28 ++++++++++++++++++- cms/sections.py | 10 +++++-- cms/templates/aircox/cms/list.html | 43 +++++++++++++++++++++++------- cms/templatetags/aircox_cms.py | 6 ++++- cms/views.py | 4 +-- 5 files changed, 75 insertions(+), 16 deletions(-) diff --git a/cms/models.py b/cms/models.py index bf39b18..29aecde 100644 --- a/cms/models.py +++ b/cms/models.py @@ -7,10 +7,10 @@ from django.utils.text import slugify from django.utils.translation import ugettext as _, ugettext_lazy from django.core.urlresolvers import reverse - from django.db.models.signals import Signal, post_save from django.dispatch import receiver +import bleach from taggit.managers import TaggableManager from aircox.cms import routes @@ -52,6 +52,19 @@ class Comment(models.Model): _('comment'), ) + def make_safe(self): + self.author = bleach.clean(self.author, tags=[]) + if self.email: + self.email = bleach.clean(self.email, tags=[]) + if self.url: + self.url = bleach.clean(self.url, tags=[]) + self.content = bleach.clean( + self.content, + tags=settings.AIRCOX_CMS_BLEACH_COMMENT_TAGS, + attributes=settings.AIRCOX_CMS_BLEACH_COMMENT_ATTRS + ) + + class Post (models.Model): """ @@ -150,6 +163,19 @@ class Post (models.Model): name = route.get_view_name(name) return reverse(name, kwargs = kwargs) + def make_safe(self): + self.title = bleach.clean( + self.title, + tags=settings.AIRCOX_CMS_BLEACH_TITLE_TAGS, + attributes=settings.AIRCOX_CMS_BLEACH_TITLE_ATTRS + ) + self.content = bleach.clean( + self.content, + tags=settings.AIRCOX_CMS_BLEACH_CONTENT_TAGS, + attributes=settings.AIRCOX_CMS_BLEACH_CONTENT_ATTRS + ) + self.tags = [ bleach.clean(tag, tags=[]) for tag in self.tags.all() ] + class Meta: abstract = True diff --git a/cms/sections.py b/cms/sections.py index f9c6e15..94a5542 100644 --- a/cms/sections.py +++ b/cms/sections.py @@ -57,7 +57,11 @@ class Section(View): def __init__ (self, *args, **kwargs): super().__init__(*args, **kwargs) - self.css_class = 'section' if not self.css_class else ' section' + + self.css_class += 'section' if not self.css_class else ' section' + if type(self) != Section: + self.css_class += ' section_' + type(self).__name__.lower() + if not self.attrs: self.attrs = {} if self.name: @@ -186,7 +190,7 @@ class List(Section): fields = [ 'date', 'time', 'image', 'title', 'content' ] image_size = '64x64' - truncate = 64 + truncate = 16 def __init__ (self, items = None, *args, **kwargs): """ @@ -222,6 +226,7 @@ class Comments(List): truncate = 0 fields = [ 'date', 'time', 'author', 'content' ] + comment_form = None success_message = ( _('Your message is awaiting for approval'), _('Your message has been published') ) error_message = _('There was an error while saving your post. ' @@ -254,6 +259,7 @@ class Comments(List): """ Forward data to this view """ + # TODO: comment satanize comment_form = CommentForm(request.POST) if comment_form.is_valid(): comment = comment_form.save(commit=False) diff --git a/cms/templates/aircox/cms/list.html b/cms/templates/aircox/cms/list.html index 7afebce..c2ef39b 100644 --- a/cms/templates/aircox/cms/list.html +++ b/cms/templates/aircox/cms/list.html @@ -3,6 +3,8 @@ {% load i18n %} {% load thumbnail %} +{% load aircox_cms %} + {% block content %}