keep filter data
This commit is contained in:
parent
559eb3f9fa
commit
fc1b423c40
2 changed files with 57 additions and 10 deletions
|
@ -19,7 +19,7 @@
|
||||||
<div class="col col-xxl mb-5" id="headline">
|
<div class="col col-xxl mb-5" id="headline">
|
||||||
<a class="text-reset link-offset-2 link-underline link-underline-opacity-0"
|
<a class="text-reset link-offset-2 link-underline link-underline-opacity-0"
|
||||||
href="{% url "blog:browse" %}"
|
href="{% url "blog:browse" %}"
|
||||||
style="display: inline-block;">
|
style="display: inline-block">
|
||||||
<h1 class="display-1 w-0">Browse</h1>
|
<h1 class="display-1 w-0">Browse</h1>
|
||||||
</a>
|
</a>
|
||||||
{# center headline on small screens #}
|
{# center headline on small screens #}
|
||||||
|
@ -40,25 +40,43 @@
|
||||||
aria-label="Search"
|
aria-label="Search"
|
||||||
placeholder="{% trans "Search" %}"
|
placeholder="{% trans "Search" %}"
|
||||||
required=""
|
required=""
|
||||||
|
{% if filters.search %}value="{{ filters.search }}"{% endif %}
|
||||||
id="id_search">
|
id="id_search">
|
||||||
</div>
|
</div>
|
||||||
<div class="py-2">
|
<div class="py-2">
|
||||||
<select class="form-select py-2"
|
<select class="form-select py-2"
|
||||||
aria-label="Large select example"
|
aria-label="Large select example"
|
||||||
name="category">
|
name="category">
|
||||||
<option value="" selected>{% trans "select category" %}</option>
|
<option value="">{% trans "select category" %}</option>
|
||||||
{% for category in categories %}<option value="{{ category.slug }}">{{ category.name }}</option>{% endfor %}
|
{% for category in categories %}
|
||||||
|
<option {% if filters.category.slug == category.slug %}selected{% endif %}
|
||||||
|
value="{{ category.slug }}">{{ category.name }}</option>
|
||||||
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="py-2">
|
<div class="py-2">
|
||||||
<input class="tagify" name="keywords" placeholder="{% trans "Keywords" %}">
|
<input class="tagify"
|
||||||
|
name="keywords"
|
||||||
|
placeholder="{% trans "Keywords" %}"
|
||||||
|
{% if filters.keywords %} value="{% for keyword in filters.keywords %}{{ keyword }} {% endfor %},"
|
||||||
|
{% endif %}>
|
||||||
|
</div>
|
||||||
|
<div class="py-2">
|
||||||
|
<button id="filter-button"
|
||||||
|
class="btn bg-primary fw-bold py-2 float-end"
|
||||||
|
type="submit">{% trans "Filter" %}</button>
|
||||||
|
<script>
|
||||||
|
if (screen.width < 480) {
|
||||||
|
col = document.getElementById("filter-button")
|
||||||
|
col.classList.add("w-100")
|
||||||
|
};
|
||||||
|
</script>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn bg-primary fw-bold py-2" type="submit">{% trans "Filter" %}</button>
|
|
||||||
<script>
|
<script>
|
||||||
// The DOM element you wish to replace with Tagify
|
var input = document.querySelector('input[class=tagify]');
|
||||||
var input = document.querySelector('input[class=tagify]');
|
new Tagify(input, {
|
||||||
// initialize Tagify on the above input node reference
|
originalInputValueFormat: valuesArr => valuesArr.map(item => item.value).join(',')
|
||||||
new Tagify(input)
|
})
|
||||||
</script>
|
</script>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -70,7 +88,7 @@
|
||||||
{# TODO: display some info if the queryset is empty #}
|
{# TODO: display some info if the queryset is empty #}
|
||||||
{# TODO: pagination #}
|
{# TODO: pagination #}
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
<div class="card col mx-auto my-2" style="min-width: 200px;">
|
<div class="card col mx-auto my-2 py-2" style="min-width: 400px;">
|
||||||
<a class="text-reset link-offset-2 link-underline link-underline-opacity-0"
|
<a class="text-reset link-offset-2 link-underline link-underline-opacity-0"
|
||||||
href=" {% url 'blog:post' post.category.slug post.slug %}">
|
href=" {% url 'blog:post' post.category.slug post.slug %}">
|
||||||
<img src="{{ post.thumbnail.url }}"
|
<img src="{{ post.thumbnail.url }}"
|
||||||
|
|
|
@ -9,6 +9,8 @@ from start.views import SearchableView
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
import ast
|
||||||
|
import json
|
||||||
|
|
||||||
class Index(TemplateView, SearchableView):
|
class Index(TemplateView, SearchableView):
|
||||||
"""
|
"""
|
||||||
|
@ -80,10 +82,37 @@ class Browse(ListView):
|
||||||
# Q(body_de__icontains=search) |
|
# Q(body_de__icontains=search) |
|
||||||
Q(slug__icontains=search)
|
Q(slug__icontains=search)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if "keywords" in self.request.GET and len(
|
||||||
|
self.request.GET["keywords"].strip()) > 0:
|
||||||
|
pass
|
||||||
return objects
|
return objects
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['featured_posts'] = BlogPost.objects.filter(featured=True)
|
context['featured_posts'] = BlogPost.objects.filter(featured=True)
|
||||||
context['categories'] = Category.objects.all()
|
context['categories'] = Category.objects.all()
|
||||||
|
|
||||||
|
context["filters"] = {}
|
||||||
|
if "category" in self.request.GET and len(
|
||||||
|
self.request.GET["category"].strip()) > 0:
|
||||||
|
category = self.request.GET["category"]
|
||||||
|
try:
|
||||||
|
category = Category.objects.get(slug=category)
|
||||||
|
context["filters"]["category"] = category
|
||||||
|
except Category.DoesNotExist:
|
||||||
|
context["filters"]["category"] = None
|
||||||
|
|
||||||
|
if "search" in self.request.GET and len(
|
||||||
|
self.request.GET["search"].strip()) > 0:
|
||||||
|
search = self.request.GET["search"]
|
||||||
|
context["filters"]["search"] = search
|
||||||
|
|
||||||
|
if "keywords" in self.request.GET and len(
|
||||||
|
self.request.GET["keywords"].strip()) > 0:
|
||||||
|
keywords = self.request.GET["keywords"]
|
||||||
|
logger.debug(f"kwr:{keywords}")
|
||||||
|
keywords = keywords.split('+')
|
||||||
|
logger.debug(f"kwt:{type(keywords)}, kw: {keywords}")
|
||||||
|
context["filters"]["keywords"] = keywords
|
||||||
return context
|
return context
|
||||||
|
|
Loading…
Add table
Reference in a new issue