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

View File

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

View File

@ -63,23 +63,35 @@
<em>Événement de portée locale</em> <em>Événement de portée locale</em>
</p> </p>
{% endif %} {% 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> </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 %} {% if event.tags %}
<p class="subentry-search"> <p class="subentry-search">
{% picto_from_name "tag" %} {% picto_from_name "tag" %}

View File

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

View File

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