keep filter data
This commit is contained in:
parent
559eb3f9fa
commit
2ea88478ec
2 changed files with 44 additions and 8 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,24 +40,36 @@
|
||||||
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" %}">
|
||||||
</div>
|
</div>
|
||||||
<button class="btn bg-primary fw-bold py-2" type="submit">{% trans "Filter" %}</button>
|
<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>
|
||||||
<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]');
|
||||||
// initialize Tagify on the above input node reference
|
|
||||||
new Tagify(input)
|
new Tagify(input)
|
||||||
</script>
|
</script>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -80,10 +80,34 @@ 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"]
|
||||||
|
context["filters"]["keywords"] = keywords
|
||||||
return context
|
return context
|
||||||
|
|
Loading…
Add table
Reference in a new issue