Make titles more relevant
This commit is contained in:
parent
373512e52d
commit
4c3b799113
2 changed files with 9 additions and 2 deletions
|
@ -12,11 +12,11 @@
|
||||||
<style>.pagination{display:flex;justify-content:space-between}</style>
|
<style>.pagination{display:flex;justify-content:space-between}</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block title %}{% endblock %}
|
{% block title %}{% if view.html_title %}{{ view.html_title }} | {% endif %}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<section>
|
<section>
|
||||||
<h2 id="blog-posts">{% block main_title %}Blog posts{% endblock %}</h2>
|
<h2 id="blog-posts">{% block main_title %}{{ view.main_title }}{% endblock %}</h2>
|
||||||
{% block search_bar %}{% endblock %}
|
{% block search_bar %}{% endblock %}
|
||||||
{% for article in articles %}
|
{% for article in articles %}
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -15,6 +15,8 @@ class BaseArticleListView(generic.ListView):
|
||||||
model = Article
|
model = Article
|
||||||
context_object_name = "articles"
|
context_object_name = "articles"
|
||||||
paginate_by = 10
|
paginate_by = 10
|
||||||
|
main_title = "Blog posts"
|
||||||
|
html_title = ""
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
@ -58,6 +60,7 @@ class ArticlesListView(PublicArticleListView):
|
||||||
|
|
||||||
class SearchArticlesListView(PublicArticleListView):
|
class SearchArticlesListView(PublicArticleListView):
|
||||||
template_name = "articles/article_search.html"
|
template_name = "articles/article_search.html"
|
||||||
|
html_title = "Search"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
@ -69,6 +72,7 @@ class SearchArticlesListView(PublicArticleListView):
|
||||||
search_expression = self.request.GET.get("s")
|
search_expression = self.request.GET.get("s")
|
||||||
if not search_expression:
|
if not search_expression:
|
||||||
return queryset.none()
|
return queryset.none()
|
||||||
|
self.html_title = f"Search results for {search_expression}"
|
||||||
search_terms = search_expression.split()
|
search_terms = search_expression.split()
|
||||||
return queryset.filter(
|
return queryset.filter(
|
||||||
reduce(operator.and_, (Q(title__icontains=term) for term in search_terms))
|
reduce(operator.and_, (Q(title__icontains=term) for term in search_terms))
|
||||||
|
@ -89,9 +93,12 @@ class SearchArticlesListView(PublicArticleListView):
|
||||||
|
|
||||||
class TagArticlesListView(PublicArticleListView):
|
class TagArticlesListView(PublicArticleListView):
|
||||||
tag = None
|
tag = None
|
||||||
|
main_title = None
|
||||||
|
html_title = None
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
self.tag = get_object_or_404(Tag, slug=self.kwargs.get("slug"))
|
self.tag = get_object_or_404(Tag, slug=self.kwargs.get("slug"))
|
||||||
|
self.main_title = self.html_title = f"{self.tag.name} articles"
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
|
Reference in a new issue