Always list all years in archive views

This commit is contained in:
Alexandre Iooss 2022-04-17 09:39:30 +02:00
parent 3afbc2b7e1
commit f29719ef78
3 changed files with 30 additions and 19 deletions

View file

@ -9,22 +9,27 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% block title %}{% blocktrans with show_year=year|date:"Y" %}Galleries for {{ show_year }}{% endblocktrans %}{% endblock %}
{% block content %}
<div class="row">
<aside class="col-md-2">
<a href="{% url 'photologue:pl-gallery-archive' %}">⬅ {% trans "View all galleries" %}</a>
</aside>
<main class="col-md-10">
{% if object_list %}
<div class="row mb-2">
{% for gallery in object_list %}
<div class="col-6 col-md-3 mb-2">
{% include "photologue/includes/gallery_sample.html" %}
</div>
{% endfor %}
<div class="row">
<aside class="col-md-2">
<h5>{% trans "Filter by year" %}</h5>
<div class="list-group">
{% for date in date_list %}
<a class="list-group-item list-group-item-action{% if date == year %} active{% endif %}" href="{% url 'photologue:pl-gallery-archive-year' date.year %}">{{ date|date:"Y" }}</a>
{% endfor %}
</div>
</aside>
<main class="col-md-10">
{% if object_list %}
<div class="row mb-2">
{% for gallery in object_list %}
<div class="col-6 col-md-3 mb-2">
{% include "photologue/includes/gallery_sample.html" %}
</div>
{% else %}
<p>{% trans "No galleries were found." %}</p>
{% endif %}
</main>
</div>
{% endfor %}
</div>
{% else %}
<p>{% trans "No galleries were found." %}</p>
{% endif %}
</main>
</div>
{% endblock %}

View file

@ -37,6 +37,12 @@ class GalleryDateView(LoginRequiredMixin):
else:
return qs.filter(photos__is_public=True).distinct()
def get_context_data(self, **kwargs):
"""Always show all years in archive"""
context = super().get_context_data(**kwargs)
context['date_list'] = self.get_queryset().dates(self.date_field, 'year', 'DESC')
return context
class GalleryArchiveIndexView(GalleryDateView, ArchiveIndexView):
pass