Ce mois-ci affiche 4 prochaines semaines

Fix #143
This commit is contained in:
Jean-Marie Favreau 2025-03-14 15:07:59 +01:00
parent 02626c3ced
commit 182d7b85ce
3 changed files with 51 additions and 18 deletions

View File

@ -432,13 +432,19 @@ class CalendarList:
class CalendarMonth(CalendarList): class CalendarMonth(CalendarList):
def __init__(self, year, month, filter, qs=None): def __init__(self, year, month, filter, qs=None, day=None):
self.year = year self.year = year
self.month = month self.month = month
self.day = day
r = calendar.monthrange(year, month) r = calendar.monthrange(year, month)
first = date(year, month, 1) if self.day is None:
last = date(year, month, r[1]) first = date(year, month, 1)
last = date(year, month, r[1])
else:
first = date(year, month, day)
last = first + timedelta(days=28)
last = last + timedelta(days=6 - last.weekday())
super().__init__(first, last, filter, qs) super().__init__(first, last, filter, qs)

View File

@ -15,27 +15,45 @@
{% endblock %} {% endblock %}
{% endblock %} {% endblock %}
{% block navigation-menu %} {% block navigation-menu %}
{% cache 90000 navigation_links_month user.is_authenticated calendar.firstdate category filter.get_url %} {% cache 90000 navigation_links_month user.is_authenticated calendar.firstdate this_month category filter.get_url %}
{% navigation_links filter category calendar "month" %} {% navigation_links filter category calendar "month" %}
{% endcache %} {% endcache %}
{% endblock %} {% endblock %}
{% block when_parameters %}{{ filter.get_url }}{% endblock %} {% block when_parameters %}{{ filter.get_url }}{% endblock %}
{% block content %} {% block content %}
{% with cache_timeout=user.is_authenticated|yesno:"30,6000" %} {% with cache_timeout=user.is_authenticated|yesno:"30,6000" %}
{% cache cache_timeout month user.is_authenticated calendar.firstdate category filter.get_url %} {% cache cache_timeout month user.is_authenticated calendar.firstdate this_month category filter.get_url %}
{% include "agenda_culturel/filter-inc.html" with filter=filter noarticle=0 %} {% include "agenda_culturel/filter-inc.html" with filter=filter noarticle=0 %}
<article> <article>
<header id="navigation"> <header id="navigation">
<div class="title small"> <div class="title small">
<h1> {% if this_month %}
{% if category %}{{ category.name }} en{% endif %} <hgroup>
{{ calendar.firstdate | date:"F o" }} <h1>
{% if filter.has_location %}à {{ filter.get_position }}{% endif %} {% if category %}{{ category.name }}{% endif %}
<a aria-label="Quand" ce mois-ci
href="#quand-popup" {% if filter.has_location %}à {{ filter.get_position }}{% endif %}
data-target="quand-popup" <a aria-label="Quand"
onClick="toggleModal(event)">{% picto_from_name "calendar" %}</a> href="#quand-popup"
</h1> data-target="quand-popup"
onClick="toggleModal(event)">{% picto_from_name "calendar" %}</a>
</h1>
<h2>
{{ calendar.firstdate|date:"F o" }}
{% if calendar.firstdate.month != calendar.lastdate.month %}/ {{ calendar.lastdate|date:"F o" }}{% endif %}
</h2>
</hgroup>
{% else %}
<h1>
{% if category %}{{ category.name }} en{% endif %}
{{ calendar.firstdate | date:"F o" }}
{% if filter.has_location %}à {{ filter.get_position }}{% endif %}
<a aria-label="Quand"
href="#quand-popup"
data-target="quand-popup"
onClick="toggleModal(event)">{% picto_from_name "calendar" %}</a>
</h1>
{% endif %}
</div> </div>
<div class="left"> <div class="left">
{% if calendar.firstdate|shift_day:-1|not_before_first %} {% if calendar.firstdate|shift_day:-1|not_before_first %}
@ -110,7 +128,13 @@
<header {% if day.is_today %}id="today"{% endif %}> <header {% if day.is_today %}id="today"{% endif %}>
<h3> <h3>
<a href="{{ day.date | url_day:category }}?{{ filter.get_url }}" <a href="{{ day.date | url_day:category }}?{{ filter.get_url }}"
class="visible-link">{{ day.date | date:"l j" }}</a> class="visible-link">
{% if day.date.day == 1 and this_month or day.date == calendar.firstdate and this_month %}
{{ day.date | date:"l j F" }}
{% else %}
{{ day.date | date:"l j" }}
{% endif %}
</a>
</h3> </h3>
</header> </header>
{% if day.events %} {% if day.events %}

View File

@ -236,6 +236,10 @@ def home(request, cat=None):
def month_view(request, year=None, month=None, cat=None): def month_view(request, year=None, month=None, cat=None):
now = date.today() now = date.today()
if year is None and month is None:
day = now.day
else:
day = None
if year is None: if year is None:
year = now.year year = now.year
if month is None: if month is None:
@ -266,12 +270,11 @@ def month_view(request, year=None, month=None, cat=None):
if filter.has_category_parameters(): if filter.has_category_parameters():
return HttpResponseRedirect(filter.get_new_url()) return HttpResponseRedirect(filter.get_new_url())
cmonth = CalendarMonth(year, month, filter) cmonth = CalendarMonth(year, month, filter, day=day)
context = { context = {
"year": year,
"month": cmonth.get_month_name(),
"calendar": cmonth, "calendar": cmonth,
"this_month": day is not None,
"filter": filter, "filter": filter,
"category": category, "category": category,
"init_date": now if cmonth.today_in_calendar() else cmonth.firstdate, "init_date": now if cmonth.today_in_calendar() else cmonth.firstdate,