ajout d'un affichage des événements concurrents (en même temps)

This commit is contained in:
Jean-Marie Favreau 2024-01-12 14:57:26 +01:00
parent 99047597bd
commit a578e3d70c
6 changed files with 74 additions and 19 deletions

View File

@ -21,7 +21,7 @@ from datetime import time, timedelta, date
from django.utils.timezone import datetime
from django.utils import timezone
from .calendar import CalendarList
from .calendar import CalendarList, CalendarDay
import logging
logger = logging.getLogger(__name__)
@ -296,7 +296,6 @@ class Event(models.Model):
if self.modified_date is None or not self.is_in_importation_process():
self.modified_date = now
def get_recurrence_at_date(self, year, month, day):
dtstart = timezone.make_aware(datetime(year, month, day, 0, 0), timezone.get_default_timezone())
recurrences = self.get_recurrences_between(dtstart, dtstart)
@ -650,6 +649,41 @@ class Event(models.Model):
return imported, nb_updated, nb_draft
def set_current_date(self, date):
self.current_date = date
def get_start_end_datetimes(self, day):
if self.start_day == day:
if self.start_time is None:
dtstart = datetime.combine(self.start_day, time().min)
else:
dtstart = datetime.combine(self.start_day, self.start_time)
else:
dtstart = datetime.combine(day, time().min)
end_day = self.get_consolidated_end_day()
if end_day == day:
if self.end_time is None:
dtend = datetime.combine(end_day, time().max)
else:
dtend = datetime.combine(end_day, self.end_time)
else:
dtend = datetime.combine(day, time().max)
return dtstart, dtend
def get_concurrent_events(self):
day = self.current_date if hasattr(self, "current_date") else self.start_day
day_events = CalendarDay(self.start_day).get_events()
return [e for e in day_events if e != self and self.is_concurrent_event(e, day) and e.status == Event.STATUS.PUBLISHED]
def is_concurrent_event(self, e, day):
dtstart, dtend = self.get_start_end_datetimes(day)
e_dtstart, e_dtend = e.get_start_end_datetimes(day)
return (dtstart <= e_dtstart <= dtend) or (e_dtstart <= dtstart <= e_dtend)

View File

@ -23,9 +23,9 @@
</article>
<article>
<head>
<header>
<p class="message warning"><strong>Attention&nbsp:</strong> n'utilisez pas le formulaire ci-dessous pour proposer un événement, il sera ignoré. Utilisez plutôt la page <a href="{% url 'add_event' %}">ajouter un événement</a>.</p>
</head>
</header>
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Envoyer">

View File

@ -68,7 +68,7 @@
<aside>
<article>
<head>
<header>
<h2>En résumé</h2>
{% if events|length == 0 %}
<p class="remarque">Il n'y a pas d'événement le {{ day }}</p>
@ -90,13 +90,13 @@
</ul>
</nav>
{% endif %}
</head>
</header>
</article>
<article>
<head>
<header>
<h2>Voir aussi</h2>
</head>
</header>
<a role="button" href="{% url 'week_view' day.year day|week %}?{{ filter.get_url }}">Toute la semaine</a>
</article>
</aside>

View File

@ -15,11 +15,30 @@
<div class="grid two-columns">
{% include "agenda_culturel/single-event/event-single-inc.html" with event=event filter=filter %}
<aside>
{% with event.get_concurrent_events as concurrent_events %}
{% if concurrent_events %}
<article>
<header>
<h2>En même temps</h2>
<p class="remarque">{% if concurrent_events.count > 1 %}Plusieurs événements se déroulent en même temps.{% else %}Un autre événement se déroule en même temps.{% endif %}</p>
</header>
<nav>
<ul>
{% for e in concurrent_events %}
<li>
<a href="{{ e.get_absolute_url }}">{{ e.title }}</a>
</li>
{% endfor %}
</ul>
</nav>
</article>
{% endif %}
{% endwith %}
<!-- TODO: en même temps -->
<article>
{% with event.get_nb_events_same_dates as nb_events_same_dates %}
{% with nb_events_same_dates|length as c_dates %}
<head>
<header>
<h2>Voir aussi</h2>
{% if c_dates != 1 %}
<p class="remarque">
@ -32,7 +51,7 @@
que l'événement affiché.
</p>
{% endif %}
</head>
</header>
<nav>
{% if c_dates == 1 %}
<a role="button" href="{% url 'day_view' nb_events_same_dates.0.1.year nb_events_same_dates.0.1.month nb_events_same_dates.0.1.day %}">Toute la journée</a>
@ -51,7 +70,7 @@
</article>
{% if event.possibly_duplicated %}
<article>
<head>
<header>
<h2>Possibles doublons</h2>
<p class="remarque">Notre algorithme a détecté que l'événement affiché pourrait être dupliqué sur l'agenda, et consultable dans
{% if event.get_possibly_duplicated.count == 1 %}
@ -60,7 +79,7 @@
d'autres versions
{% endif %}
ci-dessous.</p>
</head>
</header>
<nav>
<ul>
{% for e in event.get_possibly_duplicated %}

View File

@ -3,9 +3,9 @@
{% load duplicated_extra %}
<aside>
<article>
<head>
<header>
<h2>Consulter</h2>
</head>
</header>
<nav>
<ul>
<li><a {% if current == "tags" %}class="selected" {% endif %}href="{% url 'view_all_tags' %}">Toutes les étiquettes</a></li>
@ -13,9 +13,9 @@
</nav>
</article>
<article>
<head>
<header>
<h2>Administrer</h2>
</head>
</header>
<nav>
<ul>
<li><a {% if current == "moderation" %}class="selected" {% endif %}href="{% url 'moderation' %}">Derniers événements soumis</a>{% show_badges_events "left" %}</li>
@ -26,9 +26,9 @@
</nav>
</article>
<article>
<head>
<header>
<h2>Configurer</h2>
</head>
</header>
<nav>
<ul>
<li><a href="{% url 'admin:index' %}">Administration de django</a></li>

View File

@ -222,7 +222,9 @@ class EventDetailView(UserPassesTestMixin, DetailView):
y = self.kwargs["year"]
m = self.kwargs["month"]
d = self.kwargs["day"]
return o.get_recurrence_at_date(y, m, d)
obj = o.get_recurrence_at_date(y, m, d)
obj.set_current_date(date(y, m, d))
return obj
@login_required(login_url="/accounts/login/")