From 1ca9667ac9e5b247c4d2db428add744f5ef5db4e Mon Sep 17 00:00:00 2001
From: Jean-Marie Favreau
Date: Wed, 24 Apr 2024 13:59:24 +0200
Subject: [PATCH] =?UTF-8?q?Fix=20#112=20:=20=C3=A9l=C3=A9ments=20r=C3=A9cu?=
=?UTF-8?q?rrents=20et=20relatedto?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../custom_extractors/lacomedie.py | 2 +-
.../import_tasks/custom_extractors/lacoope.py | 2 +-
.../custom_extractors/lapucealoreille.py | 2 +-
.../custom_extractors/lefotomat.py | 2 +-
src/agenda_culturel/import_tasks/extractor.py | 4 ++--
.../import_tasks/extractor_facebook.py | 4 ++--
.../import_tasks/extractor_ical.py | 23 +++++++++++++++----
.../import_tasks/generic_extractors.py | 4 ++--
src/agenda_culturel/models.py | 8 ++-----
.../categorise_events_form.html | 2 +-
.../agenda_culturel/date-times-inc.html | 8 +++----
.../single-event/event-in-flat-list-inc.html | 2 +-
.../event-in-list-by-day-inc.html | 2 +-
.../single-event/event-in-list-inc.html | 2 +-
.../single-event/event-modal-inc.html | 2 +-
.../single-event/event-single-inc.html | 2 +-
16 files changed, 40 insertions(+), 31 deletions(-)
diff --git a/src/agenda_culturel/import_tasks/custom_extractors/lacomedie.py b/src/agenda_culturel/import_tasks/custom_extractors/lacomedie.py
index a6d45b0..fcb0664 100644
--- a/src/agenda_culturel/import_tasks/custom_extractors/lacomedie.py
+++ b/src/agenda_culturel/import_tasks/custom_extractors/lacomedie.py
@@ -65,5 +65,5 @@ class CExtractor(TwoStepsExtractor):
url_human = event_url
- self.add_event_with_props(event_url, None, None, None, None, description, [], recurrences=None, uuid=event_url, url_human=url_human, published=published, image=image)
+ self.add_event_with_props(event_url, None, None, None, None, description, [], recurrences=None, uuids=[event_url], url_human=url_human, published=published, image=image)
diff --git a/src/agenda_culturel/import_tasks/custom_extractors/lacoope.py b/src/agenda_culturel/import_tasks/custom_extractors/lacoope.py
index 12569a8..363c355 100644
--- a/src/agenda_culturel/import_tasks/custom_extractors/lacoope.py
+++ b/src/agenda_culturel/import_tasks/custom_extractors/lacoope.py
@@ -60,5 +60,5 @@ class CExtractor(TwoStepsExtractor):
location = CExtractor.nom_lieu
url_human = event_url
- self.add_event_with_props(event_url, title, category, start_day, location, description, tags, recurrences=None, uuid=event_url, url_human=url_human, start_time=start_time, end_day=end_day, end_time=end_time, published=published, image=image)
+ self.add_event_with_props(event_url, title, category, start_day, location, description, tags, recurrences=None, uuids=[event_url], url_human=url_human, start_time=start_time, end_day=end_day, end_time=end_time, published=published, image=image)
diff --git a/src/agenda_culturel/import_tasks/custom_extractors/lapucealoreille.py b/src/agenda_culturel/import_tasks/custom_extractors/lapucealoreille.py
index cd0ccba..9a978d1 100644
--- a/src/agenda_culturel/import_tasks/custom_extractors/lapucealoreille.py
+++ b/src/agenda_culturel/import_tasks/custom_extractors/lapucealoreille.py
@@ -70,4 +70,4 @@ class CExtractor(TwoStepsExtractor):
else:
description = None
- self.add_event_with_props(event_url, None, "Concert", start_day, location, description, tags, recurrences=None, uuid=event_url, url_human=url_human, start_time=start_time, end_day=end_day, end_time=end_time, published=published, image=image)
+ self.add_event_with_props(event_url, None, "Concert", start_day, location, description, tags, recurrences=None, uuids=[event_url], url_human=url_human, start_time=start_time, end_day=end_day, end_time=end_time, published=published, image=image)
diff --git a/src/agenda_culturel/import_tasks/custom_extractors/lefotomat.py b/src/agenda_culturel/import_tasks/custom_extractors/lefotomat.py
index 425dad4..dff57f7 100644
--- a/src/agenda_culturel/import_tasks/custom_extractors/lefotomat.py
+++ b/src/agenda_culturel/import_tasks/custom_extractors/lefotomat.py
@@ -68,5 +68,5 @@ class CExtractor(TwoStepsExtractor):
url_human = event_url
- self.add_event_with_props(event_url, None, None, start_day, location, description, tags, recurrences=None, uuid=event_url, url_human=url_human, start_time=start_time, end_day=end_day, end_time=end_time, published=published, image=image)
+ self.add_event_with_props(event_url, None, None, start_day, location, description, tags, recurrences=None, uuids=[event_url], url_human=url_human, start_time=start_time, end_day=end_day, end_time=end_time, published=published, image=image)
diff --git a/src/agenda_culturel/import_tasks/extractor.py b/src/agenda_culturel/import_tasks/extractor.py
index d9b9b59..eff1feb 100644
--- a/src/agenda_culturel/import_tasks/extractor.py
+++ b/src/agenda_culturel/import_tasks/extractor.py
@@ -118,7 +118,7 @@ class Extractor(ABC):
def clear_events(self):
self.events = []
- def add_event(self, title, category, start_day, location, description, tags, uuid, recurrences=None, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False, image=None, image_alt=None):
+ def add_event(self, title, category, start_day, location, description, tags, uuids, recurrences=None, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False, image=None, image_alt=None):
if title is None:
print("ERROR: cannot import an event without name")
return
@@ -130,7 +130,7 @@ class Extractor(ABC):
"title": title,
"category": category,
"start_day": start_day,
- "uuid": uuid,
+ "uuids": uuids,
"location": location,
"description": description,
"tags": tags,
diff --git a/src/agenda_culturel/import_tasks/extractor_facebook.py b/src/agenda_culturel/import_tasks/extractor_facebook.py
index 43913ba..7ebd44b 100644
--- a/src/agenda_culturel/import_tasks/extractor_facebook.py
+++ b/src/agenda_culturel/import_tasks/extractor_facebook.py
@@ -152,8 +152,8 @@ class FacebookEventExtractor(Extractor):
"location": self.get_element("event_place_name"),
"description": self.get_element("description"),
"tags": [],
- "uuid": url,
- "url_human": url,
+ "uuids": [url],
+ "url_human": url,
"start_time": self.get_element_time("start_timestamp"),
"end_day": self.get_element_date("end_timestamp"),
"end_time": self.get_element_time("end_timestamp"),
diff --git a/src/agenda_culturel/import_tasks/extractor_ical.py b/src/agenda_culturel/import_tasks/extractor_ical.py
index 63ad97a..9d4d3d9 100644
--- a/src/agenda_culturel/import_tasks/extractor_ical.py
+++ b/src/agenda_culturel/import_tasks/extractor_ical.py
@@ -92,6 +92,15 @@ class ICALExtractor(Extractor):
self.uuids[uuid] = 1
event_url = url + "#" + uuid
+ uuidrel = None
+ related_to = self.get_item_from_vevent(event, "RELATED-TO")
+ if related_to is not None:
+ if related_to in self.uuids:
+ self.uuids[related_to] += 1
+ uuidrel = url + "#" + related_to + ":{:04}".format(self.uuids[related_to] - 1)
+ # possible limitation: if the ordering is not original then related
+
+
tags = self.default_value_if_exists(default_values, "tags")
last_modified = self.get_item_from_vevent(event, "LAST-MODIFIED", raw = True)
@@ -114,7 +123,11 @@ class ICALExtractor(Extractor):
recurrences = None
if title is not None:
- self.add_event(title, category, start_day, location, description, tags, recurrences=recurrences, uuid=event_url, url_human=url_human, start_time=start_time, end_day=end_day, end_time=end_time, last_modified=last_modified, published=published)
+ luuids = [event_url]
+ if uuidrel is not None:
+ luuids += [uuidrel]
+ self.add_event(title, category, start_day, location, description, tags, recurrences=recurrences, uuids=luuids, url_human=url_human, start_time=start_time, end_day=end_day, end_time=end_time, last_modified=last_modified, published=published)
+
return self.get_structure()
@@ -122,9 +135,9 @@ class ICALExtractor(Extractor):
# A variation on ICAL extractor that removes any even named "Busy"
class ICALNoBusyExtractor(ICALExtractor):
- def add_event(self, title, category, start_day, location, description, tags, uuid, recurrences=None, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False, image=None, image_alt=None):
+ def add_event(self, title, category, start_day, location, description, tags, uuids, recurrences=None, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False, image=None, image_alt=None):
if title != 'Busy':
- super().add_event(title, category, start_day, location, description, tags, uuid, recurrences, url_human, start_time, end_day, end_time, last_modified, published, image, image_alt)
+ super().add_event(title, category, start_day, location, description, tags, uuids, recurrences, url_human, start_time, end_day, end_time, last_modified, published, image, image_alt)
# A variation on ICAL extractor that remove any visual composer anchors
@@ -145,5 +158,5 @@ class ICALNoVCExtractor(ICALExtractor):
result = self.parser.format(text)
return result
- def add_event(self, title, category, start_day, location, description, tags, uuid, recurrences=None, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False, image=None, image_alt=None):
- super().add_event(title, category, start_day, location, self.clean_vc(description), tags, uuid, recurrences, url_human, start_time, end_day, end_time, last_modified, published, image, image_alt)
\ No newline at end of file
+ def add_event(self, title, category, start_day, location, description, tags, uuids, recurrences=None, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False, image=None, image_alt=None):
+ super().add_event(title, category, start_day, location, self.clean_vc(description), tags, uuids, recurrences, url_human, start_time, end_day, end_time, last_modified, published, image, image_alt)
\ No newline at end of file
diff --git a/src/agenda_culturel/import_tasks/generic_extractors.py b/src/agenda_culturel/import_tasks/generic_extractors.py
index 5e8a40e..af2f08c 100644
--- a/src/agenda_culturel/import_tasks/generic_extractors.py
+++ b/src/agenda_culturel/import_tasks/generic_extractors.py
@@ -96,7 +96,7 @@ class TwoStepsExtractor(Extractor):
self.event_properties[url] = {}
self.event_properties[url]["location"] = loc
- def add_event_with_props(self, event_url, title, category, start_day, location, description, tags, uuid, recurrences=None, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False, image=None, image_alt=None):
+ def add_event_with_props(self, event_url, title, category, start_day, location, description, tags, uuids, recurrences=None, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False, image=None, image_alt=None):
if event_url in self.event_properties:
if 'tags' in self.event_properties[event_url]:
@@ -112,7 +112,7 @@ class TwoStepsExtractor(Extractor):
if 'location' in self.event_properties[event_url]:
location = self.event_properties[event_url]['location']
- self.add_event(title, category, start_day, location, description, tags, uuid, recurrences, url_human, start_time, end_day, end_time, last_modified, published, image, image_alt)
+ self.add_event(title, category, start_day, location, description, tags, uuids, recurrences, url_human, start_time, end_day, end_time, last_modified, published, image, image_alt)
@abstractmethod
diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py
index 59061ea..772c33f 100644
--- a/src/agenda_culturel/models.py
+++ b/src/agenda_culturel/models.py
@@ -407,10 +407,6 @@ class Event(models.Model):
if "category" in event_structure and event_structure["category"] is not None:
event_structure["category"] = Category.objects.get(name=event_structure["category"])
- if "uuid" in event_structure and event_structure["uuid"] is not None:
- event_structure["uuids"] = [event_structure["uuid"]]
- del event_structure["uuid"]
-
if "published" in event_structure and event_structure["published"] is not None:
if event_structure["published"]:
event_structure["status"] = Event.STATUS.PUBLISHED
@@ -618,8 +614,8 @@ class Event(models.Model):
max_date = sdate
if max_date is None or (event.end_day is not None and max_date < edate):
max_date = edate
- if len(event.uuids) > 0:
- uuids.add(event.uuids[0])
+ if event.uuids and len(event.uuids) > 0:
+ uuids |= set(event.uuids)
# imported events should be updated
event.set_in_importation_process()
diff --git a/src/agenda_culturel/templates/agenda_culturel/categorise_events_form.html b/src/agenda_culturel/templates/agenda_culturel/categorise_events_form.html
index 595aa7d..c786dbe 100644
--- a/src/agenda_culturel/templates/agenda_culturel/categorise_events_form.html
+++ b/src/agenda_culturel/templates/agenda_culturel/categorise_events_form.html
@@ -46,7 +46,7 @@
{% picto_from_name "calendar" %}
- {% if event.end_day %}du{% else %}le{% endif %}
+ {% if event.end_day and event.end_day != event.start_day %}du{% else %}le{% endif %}
{% include "agenda_culturel/date-times-inc.html" with event=event %}
diff --git a/src/agenda_culturel/templates/agenda_culturel/date-times-inc.html b/src/agenda_culturel/templates/agenda_culturel/date-times-inc.html
index 487a9a2..26aa510 100644
--- a/src/agenda_culturel/templates/agenda_culturel/date-times-inc.html
+++ b/src/agenda_culturel/templates/agenda_culturel/date-times-inc.html
@@ -1,10 +1,10 @@
{% load utils_extra %}
{{ event.start_day|date|frdate }}
-{% if event.start_time %} {% if not event.end_day %}{% if event.end_time %}de{% else %}à{% endif %}{% endif %}
+{% if event.start_time %} {% if not event.end_day or event.end_day == event.start_day %}{% if event.end_time %}de{% else %}à{% endif %}{% endif %}
{{ event.start_time }}
{% endif %}
-{% if event.end_day %}
- au {% if event.end_day %}{{ event.end_day|date|frdate }}{% endif %}
+{% if event.end_day and event.end_day != event.start_day %}
+ au {% if event.end_day and event.end_day != event.start_day %}{{ event.end_day|date|frdate }}{% endif %}
{% endif %}
-{% if event.end_time %} {% if not event.end_day|date|frdate %}jusqu'à{% endif %} {{ event.end_time }}{% endif %}
\ No newline at end of file
+{% if event.end_time %} {% if not event.end_day|date|frdate or event.end_day == event.start_day %}jusqu'à{% endif %} {{ event.end_time }}{% endif %}
\ No newline at end of file
diff --git a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-flat-list-inc.html b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-flat-list-inc.html
index 533733c..f6a078a 100644
--- a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-flat-list-inc.html
+++ b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-flat-list-inc.html
@@ -7,7 +7,7 @@
{% if event.title_hl %}{{ event.title_hl | safe }}{% else %}{{ event.title }}{% endif %}
{% picto_from_name "calendar" %}
- {% if event.end_day %}du{% else %}le{% endif %}
+ {% if event.end_day and event.end_day != event.start_day %}du{% else %}le{% endif %}
{% include "agenda_culturel/date-times-inc.html" with event=event %}
diff --git a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-by-day-inc.html b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-by-day-inc.html
index 3a4fead..dfb4d26 100644
--- a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-by-day-inc.html
+++ b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-by-day-inc.html
@@ -36,7 +36,7 @@
{% if event|need_complete_display:True %}
{% picto_from_name "calendar" %}
- {% if event.end_day %}Cet événement dure du {% else %}Cet événement a lieu le{% endif %}
+ {% if event.end_day and event.end_day != event.start_day %}Cet événement dure du {% else %}Cet événement a lieu le{% endif %}
{% include "agenda_culturel/date-times-inc.html" with event=event %}
{% endif %}
diff --git a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-inc.html b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-inc.html
index b9b9d85..ce8bb1f 100644
--- a/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-inc.html
+++ b/src/agenda_culturel/templates/agenda_culturel/single-event/event-in-list-inc.html
@@ -24,7 +24,7 @@
{% if event|need_complete_display:False %}
{% picto_from_name "calendar" %}
- {% if event.end_day %}Cet événement dure du {% else %}Cet événement a lieu le{% endif %}
+ {% if event.end_day and event.end_day != event.start_day %}Cet événement dure du {% else %}Cet événement a lieu le{% endif %}
{% include "agenda_culturel/date-times-inc.html" with event=event %}
{% endif %}
diff --git a/src/agenda_culturel/templates/agenda_culturel/single-event/event-modal-inc.html b/src/agenda_culturel/templates/agenda_culturel/single-event/event-modal-inc.html
index e99f3ca..57f1261 100644
--- a/src/agenda_culturel/templates/agenda_culturel/single-event/event-modal-inc.html
+++ b/src/agenda_culturel/templates/agenda_culturel/single-event/event-modal-inc.html
@@ -19,7 +19,7 @@
{% picto_from_name "calendar" %}
- {% if event.end_day %}du{% else %}le{% endif %}
+ {% if event.end_day and event.end_day != event.start_day %}du{% else %}le{% endif %}
{% include "agenda_culturel/date-times-inc.html" with event=event %}
diff --git a/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html b/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html
index f239b11..d8b8702 100644
--- a/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html
+++ b/src/agenda_culturel/templates/agenda_culturel/single-event/event-single-inc.html
@@ -11,7 +11,7 @@
{{ event|picto_status }} {{ event.title }}
{% picto_from_name "calendar" %}
- {% if event.end_day %}du{% else %}le{% endif %}
+ {% if event.end_day and event.end_day != event.start_day %}du{% else %}le{% endif %}
{% include "agenda_culturel/date-times-inc.html" with event=event %}