Extract common code in list views
This commit is contained in:
parent
b99e63dbcd
commit
1f91b76837
1 changed files with 17 additions and 13 deletions
|
@ -8,32 +8,36 @@ from django.views import generic
|
||||||
from articles.models import Article, Page
|
from articles.models import Article, Page
|
||||||
|
|
||||||
|
|
||||||
class ArticlesListView(generic.ListView):
|
class BaseArticleListView(generic.ListView):
|
||||||
model = Article
|
|
||||||
paginate_by = 15
|
paginate_by = 15
|
||||||
context_object_name = "articles"
|
|
||||||
queryset = Article.without_pages.filter(status=Article.PUBLISHED)
|
|
||||||
|
|
||||||
def get_context_data(self, *, object_list=None, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(object_list=object_list, **kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context["title_header"] = "Articles"
|
|
||||||
context["blog_title"] = settings.BLOG["title"]
|
context["blog_title"] = settings.BLOG["title"]
|
||||||
context["blog_description"] = settings.BLOG["description"]
|
context["blog_description"] = settings.BLOG["description"]
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class DraftsListView(generic.ListView, LoginRequiredMixin):
|
class ArticlesListView(BaseArticleListView):
|
||||||
|
model = Article
|
||||||
|
context_object_name = "articles"
|
||||||
|
queryset = Article.without_pages.filter(status=Article.PUBLISHED)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context["title_header"] = "Articles"
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class DraftsListView(BaseArticleListView, LoginRequiredMixin):
|
||||||
model = Article
|
model = Article
|
||||||
paginate_by = 15
|
|
||||||
context_object_name = "articles"
|
context_object_name = "articles"
|
||||||
queryset = Article.objects.filter(status=Article.DRAFT)
|
queryset = Article.objects.filter(status=Article.DRAFT)
|
||||||
|
|
||||||
def get_context_data(self, *, object_list=None, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(object_list=object_list, **kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context["title"] = "Drafts"
|
context["title"] = "Drafts"
|
||||||
context["title_header"] = context["title"]
|
context["title_header"] = context["title"]
|
||||||
context["blog_title"] = settings.BLOG["title"]
|
|
||||||
context["blog_description"] = settings.BLOG["description"]
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue