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 title %}{% blocktrans with show_year=year|date:"Y" %}Galleries for {{ show_year }}{% endblocktrans %}{% endblock %}
{% block content %} {% block content %}
<div class="row"> <div class="row">
<aside class="col-md-2"> <aside class="col-md-2">
<a href="{% url 'photologue:pl-gallery-archive' %}">⬅ {% trans "View all galleries" %}</a> <h5>{% trans "Filter by year" %}</h5>
</aside> <div class="list-group">
<main class="col-md-10"> {% for date in date_list %}
{% if object_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>
<div class="row mb-2"> {% endfor %}
{% for gallery in object_list %} </div>
<div class="col-6 col-md-3 mb-2"> </aside>
{% include "photologue/includes/gallery_sample.html" %} <main class="col-md-10">
</div> {% if object_list %}
{% endfor %} <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> </div>
{% else %} {% endfor %}
<p>{% trans "No galleries were found." %}</p> </div>
{% endif %} {% else %}
</main> <p>{% trans "No galleries were found." %}</p>
</div> {% endif %}
</main>
</div>
{% endblock %} {% endblock %}

View file

@ -37,6 +37,12 @@ class GalleryDateView(LoginRequiredMixin):
else: else:
return qs.filter(photos__is_public=True).distinct() 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): class GalleryArchiveIndexView(GalleryDateView, ArchiveIndexView):
pass pass