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):
def __init__(self, year, month, filter, qs=None):
def __init__(self, year, month, filter, qs=None, day=None):
self.year = year
self.month = month
self.day = day
r = calendar.monthrange(year, month)
first = date(year, month, 1)
last = date(year, month, r[1])
if self.day is None:
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)

View File

@ -15,27 +15,45 @@
{% endblock %}
{% endblock %}
{% 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" %}
{% endcache %}
{% endblock %}
{% block when_parameters %}{{ filter.get_url }}{% endblock %}
{% block content %}
{% 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 %}
<article>
<header id="navigation">
<div class="title small">
<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>
{% if this_month %}
<hgroup>
<h1>
{% if category %}{{ category.name }}{% endif %}
ce mois-ci
{% 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>
<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 class="left">
{% if calendar.firstdate|shift_day:-1|not_before_first %}
@ -110,7 +128,13 @@
<header {% if day.is_today %}id="today"{% endif %}>
<h3>
<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>
</header>
{% if day.events %}

View File

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