From f1ec525c5fdab3d41ba36fd54ab67eed5e5ecb53 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sun, 9 Mar 2025 20:59:13 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20des=20acc=C3=A8s=20rapides?= =?UTF-8?q?=20agenda?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/agenda_culturel/page-month.html | 2 +- .../agenda_culturel/page-upcoming.html | 2 +- .../templates/agenda_culturel/page-week.html | 2 +- .../templatetags/utils_extra.py | 108 ++++++++++-------- 4 files changed, 64 insertions(+), 50 deletions(-) diff --git a/src/agenda_culturel/templates/agenda_culturel/page-month.html b/src/agenda_culturel/templates/agenda_culturel/page-month.html index 11a29e1..b5ada27 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page-month.html +++ b/src/agenda_culturel/templates/agenda_culturel/page-month.html @@ -16,7 +16,7 @@ {% endblock %} {% block navigation-menu %} {% cache 90000 navigation_links_month user.is_authenticated calendar.firstdate category filter.get_url %} - {% navigation_links filter category %} + {% navigation_links filter category calendar "month" %} {% endcache %} {% endblock %} {% block when_parameters %}{{ filter.get_url }}{% endblock %} diff --git a/src/agenda_culturel/templates/agenda_culturel/page-upcoming.html b/src/agenda_culturel/templates/agenda_culturel/page-upcoming.html index eb14e4e..ec0422d 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page-upcoming.html +++ b/src/agenda_culturel/templates/agenda_culturel/page-upcoming.html @@ -10,7 +10,7 @@ {% endblock %} {% block navigation-menu %} {% cache 90000 navigation_links_upcoming user.is_authenticated calendar.firstdate filter.get_url category calendar.nb_days %} - {% navigation_links filter category %} + {% navigation_links filter category calendar "upcoming" %} {% endcache %} {% endblock %} {% block when_parameters %}{{ filter.get_url }}{% endblock %} diff --git a/src/agenda_culturel/templates/agenda_culturel/page-week.html b/src/agenda_culturel/templates/agenda_culturel/page-week.html index ae88c52..56ab0c0 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page-week.html +++ b/src/agenda_culturel/templates/agenda_culturel/page-week.html @@ -30,7 +30,7 @@ {% endblock %} {% block navigation-menu %} {% cache 90000 navigation_links_week user.is_authenticated calendar.firstdate category filter.get_url %} - {% navigation_links filter category %} + {% navigation_links filter category calendar "week" %} {% endcache %} {% endblock %} {% block when_parameters %}{{ filter.get_url }}{% endblock %} diff --git a/src/agenda_culturel/templatetags/utils_extra.py b/src/agenda_culturel/templatetags/utils_extra.py index 7954547..cc88261 100644 --- a/src/agenda_culturel/templatetags/utils_extra.py +++ b/src/agenda_culturel/templatetags/utils_extra.py @@ -2,6 +2,8 @@ from datetime import date, datetime, timedelta import calendar from string import ascii_uppercase as auc from urllib.parse import urlparse +from django.utils.formats import localize +from django.utils import dates import emoji from dateutil.relativedelta import relativedelta @@ -187,58 +189,70 @@ def no_emoji(text): @register.simple_tag -def navigation_links(filter, category): +def navigation_links(filter, category, calendar, current_view): extra = "?" + filter.get_url() - if category is None: - result = ( - '
  • aujourd'hui
  • " - ) + + result = "" + + extra_path = "" if category is None else "_category" + + if not calendar.today_in_calendar(): + if current_view == "upcoming": + params = {} + if category: + params["cat"] = category.slug + params["year"] = calendar.firstdate.year + params["week"] = calendar.firstdate.isocalendar()[1] + result += ( + '
  • semaine du ' + + localize(calendar.firstdate) + + "
  • " + ) + + if current_view != "month": + params = {} + if category: + params["cat"] = category.slug + + days = [calendar.firstdate] + if calendar.firstdate.month != calendar.lastdate.month: + days.append(calendar.lastdate) + for d in days: + params["year"] = d.year + params["month"] = d.month + result += ( + '
  • ' + + dates.MONTHS[d.month] + + " " + + str(d.year) + + "
  • " + ) + + kwargs = {} + if category: + kwargs["cat"] = category.slug + + for t in [ + ("aujourdhui", "aujourd'hui"), + ("a_venir", "ces jours-ci"), + ("cette_semaine", "cette semaine"), + ("ce_mois_ci", "ce mois-ci"), + ]: result += ( '
  • ces jours-ci
  • ' - ) - result += ( - '
  • cette semaine
  • ' - ) - result += ( - '
  • ce mois-ci
  • ' - ) - else: - result = ( - '
  • aujourd'hui
  • " - ) - result += ( - '
  • à venir
  • ' - ) - result += ( - '
  • cette semaine
  • ' - ) - result += ( - '
  • ce mois-ci
  • ' + + '">' + + t[1] + + "" ) + return mark_safe(result)