more DRY cosmetics
This commit is contained in:
parent
7a2442d6ec
commit
e9398dd79b
1 changed files with 11 additions and 23 deletions
|
@ -52,16 +52,20 @@ 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):
|
||||||
context_object_name = 'post_list'
|
context_object_name = 'post_list'
|
||||||
|
paginate_by = get_setting('PAGINATION')
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
class PostListView(BaseBlogListView, ListView):
|
||||||
|
view_url_name = 'djangocms_blog:posts-latest'
|
||||||
|
|
||||||
def get_paginate_by(self, queryset):
|
def get_paginate_by(self, queryset):
|
||||||
return (self.config and self.config.paginate_by) or get_setting('PAGINATION')
|
return (self.config and self.config.paginate_by) or get_setting('PAGINATION')
|
||||||
|
|
||||||
|
@ -101,13 +105,10 @@ class PostDetailView(TranslatableSlugMixin, BaseBlogView, DetailView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class PostArchiveView(BaseBlogView, ListView):
|
class PostArchiveView(BaseBlogListView, ListView):
|
||||||
context_object_name = 'post_list'
|
|
||||||
base_template_name = 'post_list.html'
|
|
||||||
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):
|
||||||
|
@ -124,14 +125,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):
|
||||||
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):
|
||||||
|
@ -142,14 +139,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):
|
||||||
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):
|
||||||
|
@ -161,15 +154,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):
|
||||||
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
|
||||||
|
@ -195,5 +184,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
|
||||||
|
|
Loading…
Reference in a new issue