On supprime la navigation vers les pages 1 an avant maintenant et 1 an après maintenant

This commit is contained in:
Jean-Marie Favreau 2024-08-31 13:52:47 +02:00
parent 355eb6c5f7
commit 6d3033ba37
5 changed files with 42 additions and 10 deletions

View File

@ -3,7 +3,6 @@ import calendar
from django.db.models import Q from django.db.models import Q
from django.utils import timezone from django.utils import timezone
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -38,19 +38,27 @@
<header> <header>
<div class="title"><h1>{{ day | date:"l j F Y"|frdate }}</h1></div> <div class="title"><h1>{{ day | date:"l j F Y"|frdate }}</h1></div>
<div class="navigation"> <div class="navigation">
<div> {% if day|shift_day:-1|not_before_first %}
{% with day|shift_day:-1 as pred_day %} {% if day|not_after_last %}
<a role="button" href="{% url 'day_view' pred_day.year pred_day.month pred_day.day %}?{{ filter.get_url }}"> <div>
{% picto_from_name "chevron-left" %} précédent</a> {% with day|shift_day:-1 as pred_day %}
{% endwith %} <a role="button" href="{% url 'day_view' pred_day.year pred_day.month pred_day.day %}?{{ filter.get_url }}">
</div> {% picto_from_name "chevron-left" %} précédent</a>
<div class="right"> {% endwith %}
</div>
{% endif %}
{% endif %}
{% if day|shift_day:-1|not_before_first %}
{% if day|not_after_last %}
<div class="right">
{% with day|shift_day:1 as next_day %} {% with day|shift_day:1 as next_day %}
<a role="button" href="{% url 'day_view' next_day.year next_day.month next_day.day %}?{{ filter.get_url }}">suivant <a role="button" href="{% url 'day_view' next_day.year next_day.month next_day.day %}?{{ filter.get_url }}">suivant
{% picto_from_name "chevron-right" %} {% picto_from_name "chevron-right" %}
</a> </a>
{% endwith %} {% endwith %}
{% endif %}
</div> </div>
{% endif %}
</div> </div>
</header> </header>
</article> </article>

View File

@ -35,14 +35,22 @@
<div class="title"><h1>{{ calendar.firstdate | date:"F o" }}</h1></div> <div class="title"><h1>{{ calendar.firstdate | date:"F o" }}</h1></div>
<div class="navigation"> <div class="navigation">
<div> <div>
{% if calendar.firstdate|shift_day:-1|not_before_first %}
{% if calendar.lastdate|not_after_last %}
<a role="button" href="{% url 'month_view' calendar.previous_month.year calendar.previous_month.month %}?{{ filter.get_url }}"> <a role="button" href="{% url 'month_view' calendar.previous_month.year calendar.previous_month.month %}?{{ filter.get_url }}">
{% picto_from_name "chevron-left" %} précédent</a> {% picto_from_name "chevron-left" %} précédent</a>
</div> </div>
{% endif %}
{% endif %}
{% if calendar.lastdate|shift_day:+1|not_after_last %}
{% if calendar.lastdate|not_before_first %}
<div class="right"> <div class="right">
<a role="button" href="{% url 'month_view' calendar.next_month.year calendar.next_month.month %}?{{ filter.get_url }}">suivant <a role="button" href="{% url 'month_view' calendar.next_month.year calendar.next_month.month %}?{{ filter.get_url }}">suivant
{% picto_from_name "chevron-right" %} {% picto_from_name "chevron-right" %}
</a> </a>
</div> </div>
{% endif %}
{% endif %}
</div> </div>
</header> </header>
<div id="calendar"> <div id="calendar">

View File

@ -31,14 +31,22 @@
<div class="title"><h1>Semaine du {{ calendar.calendar_days_list.0.date |date|frdate }}</h1></div> <div class="title"><h1>Semaine du {{ calendar.calendar_days_list.0.date |date|frdate }}</h1></div>
<div class="navigation"> <div class="navigation">
<div> <div>
<a role="button" href="{% url 'week_view' calendar.previous_week.year calendar.previous_week|week %}?{{ filter.get_url }}"> {% if calendar.firstdate|shift_day:-1|not_before_first %}
{% if calendar.lastdate|not_after_last %}
<a role="button" href="{% url 'week_view' calendar.previous_week.year calendar.previous_week|week %}?{{ filter.get_url }}">
{% picto_from_name "chevron-left" %} précédente</a> {% picto_from_name "chevron-left" %} précédente</a>
{% endif %}
{% endif %}
</div> </div>
{% if calendar.lastdate|shift_day:+1|not_after_last %}
{% if calendar.lastdate|not_before_first %}
<div class="right"> <div class="right">
<a role="button" href="{% url 'week_view' calendar.next_week.year calendar.next_week|week %}?{{ filter.get_url }}">suivante <a role="button" href="{% url 'week_view' calendar.next_week.year calendar.next_week|week %}?{{ filter.get_url }}">suivante
{% picto_from_name "chevron-right" %} {% picto_from_name "chevron-right" %}
</a> </a>
</div> </div>
{% endif %}
{% endif %}
</div> </div>
</header> </header>
<div id="calendar"> <div id="calendar">

View File

@ -3,7 +3,8 @@ from django.utils.safestring import mark_safe
from django.template.defaultfilters import stringfilter from django.template.defaultfilters import stringfilter
from urllib.parse import urlparse from urllib.parse import urlparse
from datetime import timedelta, date from datetime import timedelta, date, datetime
from dateutil.relativedelta import relativedelta
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.templatetags.static import static from django.templatetags.static import static
from string import ascii_uppercase as auc from string import ascii_uppercase as auc
@ -27,6 +28,14 @@ def week(d):
return d.isocalendar()[1] return d.isocalendar()[1]
@register.filter
def not_before_first(d):
return d >= datetime.now().date() - relativedelta(years=1)
@register.filter
def not_after_last(d):
return d <= datetime.now().date() + relativedelta(years=1)
@register.filter @register.filter
def shift_day(d, shift): def shift_day(d, shift):
return d + timedelta(days=shift) return d + timedelta(days=shift)