work on pagination
This commit is contained in:
parent
94b9aab006
commit
e0a268505e
|
@ -7,10 +7,10 @@ from django.utils.text import slugify
|
||||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
|
||||||
|
|
||||||
from django.db.models.signals import Signal, post_save
|
from django.db.models.signals import Signal, post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
import bleach
|
||||||
from taggit.managers import TaggableManager
|
from taggit.managers import TaggableManager
|
||||||
|
|
||||||
from aircox.cms import routes
|
from aircox.cms import routes
|
||||||
|
@ -52,6 +52,19 @@ class Comment(models.Model):
|
||||||
_('comment'),
|
_('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):
|
class Post (models.Model):
|
||||||
"""
|
"""
|
||||||
|
@ -150,6 +163,19 @@ class Post (models.Model):
|
||||||
name = route.get_view_name(name)
|
name = route.get_view_name(name)
|
||||||
return reverse(name, kwargs = kwargs)
|
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:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,11 @@ class Section(View):
|
||||||
|
|
||||||
def __init__ (self, *args, **kwargs):
|
def __init__ (self, *args, **kwargs):
|
||||||
super().__init__(*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:
|
if not self.attrs:
|
||||||
self.attrs = {}
|
self.attrs = {}
|
||||||
if self.name:
|
if self.name:
|
||||||
|
@ -186,7 +190,7 @@ class List(Section):
|
||||||
|
|
||||||
fields = [ 'date', 'time', 'image', 'title', 'content' ]
|
fields = [ 'date', 'time', 'image', 'title', 'content' ]
|
||||||
image_size = '64x64'
|
image_size = '64x64'
|
||||||
truncate = 64
|
truncate = 16
|
||||||
|
|
||||||
def __init__ (self, items = None, *args, **kwargs):
|
def __init__ (self, items = None, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -222,6 +226,7 @@ class Comments(List):
|
||||||
truncate = 0
|
truncate = 0
|
||||||
fields = [ 'date', 'time', 'author', 'content' ]
|
fields = [ 'date', 'time', 'author', 'content' ]
|
||||||
|
|
||||||
|
comment_form = None
|
||||||
success_message = ( _('Your message is awaiting for approval'),
|
success_message = ( _('Your message is awaiting for approval'),
|
||||||
_('Your message has been published') )
|
_('Your message has been published') )
|
||||||
error_message = _('There was an error while saving your post. '
|
error_message = _('There was an error while saving your post. '
|
||||||
|
@ -254,6 +259,7 @@ class Comments(List):
|
||||||
"""
|
"""
|
||||||
Forward data to this view
|
Forward data to this view
|
||||||
"""
|
"""
|
||||||
|
# TODO: comment satanize
|
||||||
comment_form = CommentForm(request.POST)
|
comment_form = CommentForm(request.POST)
|
||||||
if comment_form.is_valid():
|
if comment_form.is_valid():
|
||||||
comment = comment_form.save(commit=False)
|
comment = comment_form.save(commit=False)
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load thumbnail %}
|
{% load thumbnail %}
|
||||||
|
|
||||||
|
{% load aircox_cms %}
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -72,18 +74,39 @@
|
||||||
{% if not page_obj or embed %}
|
{% if not page_obj or embed %}
|
||||||
<a href="{{list.url}}" title={% trans "More elements" %}>⇲</a>
|
<a href="{{list.url}}" title={% trans "More elements" %}>⇲</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
{# FIXME: page numbers #}
|
{% with page_obj.paginator.num_pages as num_pages %}
|
||||||
{% if page_obj.has_previous %}
|
{% if page_obj.has_previous %}
|
||||||
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
|
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<span class="current">
|
{% if page_obj.number > 3 %}
|
||||||
{{ page_obj.number }} / {{ page_obj.paginator.num_pages }}
|
<a href="?page=1">1</a>
|
||||||
</span>
|
{% if page_obj.number > 4 %}
|
||||||
|
…
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for i in page_obj.number|around:2 %}
|
||||||
|
{% if i == page_obj.number %}
|
||||||
|
{{ page_obj.number }}
|
||||||
|
{% elif i > 0 and i <= num_pages %}
|
||||||
|
<a href="?page={{ i }}">{{ i }}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% with page_obj.number|add:"2" as max %}
|
||||||
|
{% if max < num_pages %}
|
||||||
|
{% if max|add:"1" < num_pages %}
|
||||||
|
…
|
||||||
|
{% endif %}
|
||||||
|
<a href="?page={{ num_pages }}">{{ num_pages }}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
|
|
||||||
{% if page_obj.has_next %}
|
{% if page_obj.has_next %}
|
||||||
<a href="?page={{ page_obj.next_page_number }}">next</a>
|
<a href="?page={{ page_obj.next_page_number }}">next</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</nav>
|
</nav>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -5,7 +5,7 @@ register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name='threads')
|
@register.filter(name='threads')
|
||||||
def threads (post, sep = '/'):
|
def threads(post, sep = '/'):
|
||||||
"""
|
"""
|
||||||
print a list of all parents, from top to bottom
|
print a list of all parents, from top to bottom
|
||||||
"""
|
"""
|
||||||
|
@ -20,4 +20,8 @@ def threads (post, sep = '/'):
|
||||||
for post in posts if post.published
|
for post in posts if post.published
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@register.filter(name='around')
|
||||||
|
def around(page_num, n):
|
||||||
|
return range(page_num-n, page_num+n+1)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ class PostListView(PostBaseView, ListView):
|
||||||
"""
|
"""
|
||||||
template_name = 'aircox/cms/list.html'
|
template_name = 'aircox/cms/list.html'
|
||||||
allow_empty = True
|
allow_empty = True
|
||||||
paginate_by = 25
|
paginate_by = 3
|
||||||
model = None
|
model = None
|
||||||
|
|
||||||
route = None
|
route = None
|
||||||
|
@ -102,7 +102,7 @@ class PostListView(PostBaseView, ListView):
|
||||||
if not self.list:
|
if not self.list:
|
||||||
import aircox.cms.sections as sections
|
import aircox.cms.sections as sections
|
||||||
self.list = sections.List(
|
self.list = sections.List(
|
||||||
truncate = 64,
|
truncate = 32,
|
||||||
fields = [ 'date', 'time', 'image', 'title', 'content' ],
|
fields = [ 'date', 'time', 'image', 'title', 'content' ],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user