Amélioration de la gestion des récurrences

Fix #65
Fix #224
See #304
This commit is contained in:
Jean-Marie Favreau 2025-04-11 22:17:08 +02:00
parent f310f9f58b
commit c180e3c623
5 changed files with 103 additions and 51 deletions

View File

@ -1656,10 +1656,12 @@ class Event(models.Model):
return result
def has_recurrences(self):
# TODO: see https://forge.chapril.org/jmtrivial/agenda_culturel/issues/65
return self.recurrences is not None and len(self.recurrences.rrules) != 0
return self.recurrences is not None and (
len(self.recurrences.rrules) != 0 or len(self.recurrences.rdates) != 0
)
def update_recurrence_dtstartend(self):
# get start and end date and time
sday = (
date.fromisoformat(self.start_day)
if isinstance(self.start_day, str)
@ -1681,6 +1683,7 @@ class Event(models.Model):
else time() if self.end_time is None else self.end_time
)
# updating start and end date for database efficiency
self.recurrence_dtstart = datetime.combine(sday, stime)
if not self.has_recurrences():
if self.end_day is None:
@ -1689,7 +1692,8 @@ class Event(models.Model):
self.recurrence_dtend = datetime.combine(eday, etime)
else:
if (
self.recurrences.rrules[0].until is None
len(self.recurrences.rrules) > 0
and self.recurrences.rrules[0].until is None
and self.recurrences.rrules[0].count is None
):
self.recurrence_dtend = None

View File

@ -96,12 +96,24 @@
{% if event.has_recurrences %}
<p class="footer">
{% picto_from_name "repeat" %}
<!-- TODO: see https://forge.chapril.org/jmtrivial/agenda_culturel/issues/65 -->
{% for r in event.recurrences.rrules %}
{{ r.to_text }}
{% if not forloop.first %},{% endif %}
{% endfor %}
, depuis le {{ event.recurrences.dtstart.date }}
{% if event.recurrences.rrules %}
{% for r in event.recurrences.rrules %}
{{ r.to_text }}
{% if not forloop.first %},{% endif %}
{% endfor %}
, depuis le {{ event.recurrences.dtstart.date }}
{% endif %}
{% if event.recurrences.rdates %}
les {{ event.recurrences.dtstart.date }}
{% for d in event.recurrences.rdates %}
{% if forloop.last %}
et
{% else %}
,
{% endif %}
{{ d.date }}
{% endfor %}
{% endif %}
</p>
{% endif %}
</div>

View File

@ -63,23 +63,35 @@
<em>Événement de portée locale</em>
</p>
{% endif %}
{% if event.has_recurrences %}
<p class="subentry-search">
{% picto_from_name "repeat" %}
{% if event.recurrences.rrules %}
{% for r in event.recurrences.rrules %}
{{ r.to_text }}
{% if not forloop.first %},{% endif %}
{% endfor %}
depuis le
{% if event.recurrences.dtstart.date %}
{{ event.recurrences.dtstart.date }}
{% else %}
{{ event.start_day }}
{% endif %}
{% endif %}
{% if event.recurrences.rdates %}
les {{ event.recurrences.dtstart.date }}
{% for d in event.recurrences.rdates %}
{% if forloop.last %}
et
{% else %}
,
{% endif %}
{{ d.date }}
{% endfor %}
{% endif %}
</p>
{% endif %}
</header>
{% if event.has_recurrences %}
<p class="subentry-search">
{% picto_from_name "repeat" %}
<!-- TODO: see https://forge.chapril.org/jmtrivial/agenda_culturel/issues/65 -->
{% for r in event.recurrences.rrules %}
{{ r.to_text }}
{% if not forloop.first %},{% endif %}
{% endfor %}
, depuis le
{% if event.recurrences.dtstart.date %}
{{ event.recurrences.dtstart.date }}
{% else %}
{{ event.start_day }}
{% endif %}
</p>
{% endif %}
{% if event.tags %}
<p class="subentry-search">
{% picto_from_name "tag" %}

View File

@ -56,16 +56,28 @@
{% if event.has_recurrences %}
<p>
{% picto_from_name "repeat" %}
<!-- TODO: see https://forge.chapril.org/jmtrivial/agenda_culturel/issues/65 -->
{% for r in event.recurrences.rrules %}
{{ r.to_text }}
{% if not forloop.first %},{% endif %}
{% endfor %}
, depuis le
{% if event.recurrences.dtstart.date %}
{{ event.recurrences.dtstart.date }}
{% else %}
{{ event.start_day }}
{% if event.recurrences.rrules %}
{% for r in event.recurrences.rrules %}
{{ r.to_text }}
{% if not forloop.first %},{% endif %}
{% endfor %}
depuis le
{% if event.recurrences.dtstart.date %}
{{ event.recurrences.dtstart.date }}
{% else %}
{{ event.start_day }}
{% endif %}
{% endif %}
{% if event.recurrences.rdates %}
les {{ event.recurrences.dtstart.date }}
{% for d in event.recurrences.rdates %}
{% if forloop.last %}
et
{% else %}
,
{% endif %}
{{ d.date }}
{% endfor %}
{% endif %}
</p>
{% endif %}

View File

@ -179,24 +179,36 @@
{% if event.has_recurrences %}
<p class="footer">
{% picto_from_name "repeat" %}
<!-- TODO: see https://forge.chapril.org/jmtrivial/agenda_culturel/issues/65 -->
{% for r in event.recurrences.rrules %}
{{ r.to_text }}
{% if not forloop.first %},{% endif %}
{% endfor %}
, depuis le {{ event.recurrences.dtstart.date }}
{% if event.recurrences.exdates|length > 0 %}
, sauf
le{{ recurrences.exdates|length|pluralize }}
{% for e in event.recurrences.exdates %}
{% if not forloop.first %}
{% if forloop.last %}
et
{% else %}
,
{% if event.recurrences.rrules %}
{% for r in event.recurrences.rrules %}
{{ r.to_text }}
{% if not forloop.first %},{% endif %}
{% endfor %}
depuis le {{ event.recurrences.dtstart.date }}
{% if event.recurrences.exdates|length > 0 %}
, sauf
le{{ recurrences.exdates|length|pluralize }}
{% for e in event.recurrences.exdates %}
{% if not forloop.first %}
{% if forloop.last %}
et
{% else %}
,
{% endif %}
{% endif %}
{{ e.date }}
{% endfor %}
{% endif %}
{% endif %}
{% if event.recurrences.rdates %}
les {{ event.recurrences.dtstart.date }}
{% for d in event.recurrences.rdates %}
{% if forloop.last %}
et
{% else %}
,
{% endif %}
{{ e.date }}
{{ d.date }}
{% endfor %}
{% endif %}
</p>