Merge pull request #246 from frnhr/feature/fix_pagination_config

Fix pagination config
This commit is contained in:
Iacopo Spalletti 2016-05-05 14:16:24 +02:00
commit 500750c330
2 changed files with 12 additions and 29 deletions

View file

@ -14,6 +14,7 @@ History
* Fixed error with on_site filter * Fixed error with on_site filter
* Removed meta-mixin compatibility code * Removed meta-mixin compatibility code
* Changed slug size to 255 chars * Changed slug size to 255 chars
* Fixed pagination setting in list views
0.7.0 (2016-03-19) 0.7.0 (2016-03-19)
++++++++++++++++++ ++++++++++++++++++

View file

@ -19,6 +19,7 @@ User = get_user_model()
class BaseBlogView(AppConfigMixin, ViewUrlMixin): class BaseBlogView(AppConfigMixin, ViewUrlMixin):
model = Post
def get_view_url(self): def get_view_url(self):
if not self.view_url_name: if not self.view_url_name:
@ -51,14 +52,12 @@ class BaseBlogView(AppConfigMixin, ViewUrlMixin):
return os.path.join(template_path, self.base_template_name) return os.path.join(template_path, self.base_template_name)
class PostListView(BaseBlogView, ListView): class BaseBlogListView(BaseBlogView):
model = Post
context_object_name = 'post_list' context_object_name = 'post_list'
base_template_name = 'post_list.html' base_template_name = 'post_list.html'
view_url_name = 'djangocms_blog:posts-latest'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(PostListView, self).get_context_data(**kwargs) context = super(BaseBlogListView, self).get_context_data(**kwargs)
context['TRUNCWORDS_COUNT'] = get_setting('POSTS_LIST_TRUNCWORDS_COUNT') context['TRUNCWORDS_COUNT'] = get_setting('POSTS_LIST_TRUNCWORDS_COUNT')
return context return context
@ -67,7 +66,6 @@ class PostListView(BaseBlogView, ListView):
class PostDetailView(TranslatableSlugMixin, BaseBlogView, DetailView): class PostDetailView(TranslatableSlugMixin, BaseBlogView, DetailView):
model = Post
context_object_name = 'post' context_object_name = 'post'
base_template_name = 'post_detail.html' base_template_name = 'post_detail.html'
slug_field = 'slug' slug_field = 'slug'
@ -102,14 +100,14 @@ class PostDetailView(TranslatableSlugMixin, BaseBlogView, DetailView):
return context return context
class PostArchiveView(BaseBlogView, ListView): class PostListView(BaseBlogListView, ListView):
model = Post view_url_name = 'djangocms_blog:posts-latest'
context_object_name = 'post_list'
base_template_name = 'post_list.html'
class PostArchiveView(BaseBlogListView, ListView):
date_field = 'date_published' date_field = 'date_published'
allow_empty = True allow_empty = True
allow_future = True allow_future = True
paginate_by = get_setting('PAGINATION')
view_url_name = 'djangocms_blog:posts-archive' view_url_name = 'djangocms_blog:posts-archive'
def get_queryset(self): def get_queryset(self):
@ -126,15 +124,10 @@ class PostArchiveView(BaseBlogView, ListView):
if kwargs['year']: if kwargs['year']:
kwargs['archive_date'] = now().replace(kwargs['year'], kwargs['month'] or 1, 1) kwargs['archive_date'] = now().replace(kwargs['year'], kwargs['month'] or 1, 1)
context = super(PostArchiveView, self).get_context_data(**kwargs) context = super(PostArchiveView, self).get_context_data(**kwargs)
context['TRUNCWORDS_COUNT'] = get_setting('POSTS_LIST_TRUNCWORDS_COUNT')
return context return context
class TaggedListView(BaseBlogView, ListView): class TaggedListView(BaseBlogListView, ListView):
model = Post
context_object_name = 'post_list'
base_template_name = 'post_list.html'
paginate_by = get_setting('PAGINATION')
view_url_name = 'djangocms_blog:posts-tagged' view_url_name = 'djangocms_blog:posts-tagged'
def get_queryset(self): def get_queryset(self):
@ -145,15 +138,10 @@ class TaggedListView(BaseBlogView, ListView):
kwargs['tagged_entries'] = (self.kwargs.get('tag') kwargs['tagged_entries'] = (self.kwargs.get('tag')
if 'tag' in self.kwargs else None) if 'tag' in self.kwargs else None)
context = super(TaggedListView, self).get_context_data(**kwargs) context = super(TaggedListView, self).get_context_data(**kwargs)
context['TRUNCWORDS_COUNT'] = get_setting('POSTS_LIST_TRUNCWORDS_COUNT')
return context return context
class AuthorEntriesView(BaseBlogView, ListView): class AuthorEntriesView(BaseBlogListView, ListView):
model = Post
context_object_name = 'post_list'
base_template_name = 'post_list.html'
paginate_by = get_setting('PAGINATION')
view_url_name = 'djangocms_blog:posts-authors' view_url_name = 'djangocms_blog:posts-authors'
def get_queryset(self): def get_queryset(self):
@ -165,16 +153,11 @@ class AuthorEntriesView(BaseBlogView, ListView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs['author'] = User.objects.get(**{User.USERNAME_FIELD: self.kwargs.get('username')}) kwargs['author'] = User.objects.get(**{User.USERNAME_FIELD: self.kwargs.get('username')})
context = super(AuthorEntriesView, self).get_context_data(**kwargs) context = super(AuthorEntriesView, self).get_context_data(**kwargs)
context['TRUNCWORDS_COUNT'] = get_setting('POSTS_LIST_TRUNCWORDS_COUNT')
return context return context
class CategoryEntriesView(BaseBlogView, ListView): class CategoryEntriesView(BaseBlogListView, ListView):
model = Post
context_object_name = 'post_list'
base_template_name = 'post_list.html'
_category = None _category = None
paginate_by = get_setting('PAGINATION')
view_url_name = 'djangocms_blog:posts-category' view_url_name = 'djangocms_blog:posts-category'
@property @property
@ -200,5 +183,4 @@ class CategoryEntriesView(BaseBlogView, ListView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs['category'] = self.category kwargs['category'] = self.category
context = super(CategoryEntriesView, self).get_context_data(**kwargs) context = super(CategoryEntriesView, self).get_context_data(**kwargs)
context['TRUNCWORDS_COUNT'] = get_setting('POSTS_LIST_TRUNCWORDS_COUNT')
return context return context