Fix #112 : éléments récurrents et relatedto

This commit is contained in:
Jean-Marie Favreau 2024-04-24 13:59:24 +02:00
parent ebf992112d
commit 1ca9667ac9
16 changed files with 40 additions and 31 deletions

View File

@ -65,5 +65,5 @@ class CExtractor(TwoStepsExtractor):
url_human = event_url 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)

View File

@ -60,5 +60,5 @@ class CExtractor(TwoStepsExtractor):
location = CExtractor.nom_lieu location = CExtractor.nom_lieu
url_human = event_url 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)

View File

@ -70,4 +70,4 @@ class CExtractor(TwoStepsExtractor):
else: else:
description = None 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)

View File

@ -68,5 +68,5 @@ class CExtractor(TwoStepsExtractor):
url_human = event_url 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)

View File

@ -118,7 +118,7 @@ class Extractor(ABC):
def clear_events(self): def clear_events(self):
self.events = [] 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: if title is None:
print("ERROR: cannot import an event without name") print("ERROR: cannot import an event without name")
return return
@ -130,7 +130,7 @@ class Extractor(ABC):
"title": title, "title": title,
"category": category, "category": category,
"start_day": start_day, "start_day": start_day,
"uuid": uuid, "uuids": uuids,
"location": location, "location": location,
"description": description, "description": description,
"tags": tags, "tags": tags,

View File

@ -152,8 +152,8 @@ class FacebookEventExtractor(Extractor):
"location": self.get_element("event_place_name"), "location": self.get_element("event_place_name"),
"description": self.get_element("description"), "description": self.get_element("description"),
"tags": [], "tags": [],
"uuid": url, "uuids": [url],
"url_human": url, "url_human": url,
"start_time": self.get_element_time("start_timestamp"), "start_time": self.get_element_time("start_timestamp"),
"end_day": self.get_element_date("end_timestamp"), "end_day": self.get_element_date("end_timestamp"),
"end_time": self.get_element_time("end_timestamp"), "end_time": self.get_element_time("end_timestamp"),

View File

@ -92,6 +92,15 @@ class ICALExtractor(Extractor):
self.uuids[uuid] = 1 self.uuids[uuid] = 1
event_url = url + "#" + uuid 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") tags = self.default_value_if_exists(default_values, "tags")
last_modified = self.get_item_from_vevent(event, "LAST-MODIFIED", raw = True) last_modified = self.get_item_from_vevent(event, "LAST-MODIFIED", raw = True)
@ -114,7 +123,11 @@ class ICALExtractor(Extractor):
recurrences = None recurrences = None
if title is not 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() return self.get_structure()
@ -122,9 +135,9 @@ class ICALExtractor(Extractor):
# A variation on ICAL extractor that removes any even named "Busy" # A variation on ICAL extractor that removes any even named "Busy"
class ICALNoBusyExtractor(ICALExtractor): 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': 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 # A variation on ICAL extractor that remove any visual composer anchors
@ -145,5 +158,5 @@ class ICALNoVCExtractor(ICALExtractor):
result = self.parser.format(text) result = self.parser.format(text)
return result 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): 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, uuid, recurrences, url_human, start_time, end_day, end_time, last_modified, published, image, image_alt) 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)

View File

@ -96,7 +96,7 @@ class TwoStepsExtractor(Extractor):
self.event_properties[url] = {} self.event_properties[url] = {}
self.event_properties[url]["location"] = loc 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 event_url in self.event_properties:
if 'tags' in self.event_properties[event_url]: if 'tags' in self.event_properties[event_url]:
@ -112,7 +112,7 @@ class TwoStepsExtractor(Extractor):
if 'location' in self.event_properties[event_url]: if 'location' in self.event_properties[event_url]:
location = self.event_properties[event_url]['location'] 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 @abstractmethod

View File

@ -407,10 +407,6 @@ class Event(models.Model):
if "category" in event_structure and event_structure["category"] is not None: if "category" in event_structure and event_structure["category"] is not None:
event_structure["category"] = Category.objects.get(name=event_structure["category"]) 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 "published" in event_structure and event_structure["published"] is not None:
if event_structure["published"]: if event_structure["published"]:
event_structure["status"] = Event.STATUS.PUBLISHED event_structure["status"] = Event.STATUS.PUBLISHED
@ -618,8 +614,8 @@ class Event(models.Model):
max_date = sdate max_date = sdate
if max_date is None or (event.end_day is not None and max_date < edate): if max_date is None or (event.end_day is not None and max_date < edate):
max_date = edate max_date = edate
if len(event.uuids) > 0: if event.uuids and len(event.uuids) > 0:
uuids.add(event.uuids[0]) uuids |= set(event.uuids)
# imported events should be updated # imported events should be updated
event.set_in_importation_process() event.set_in_importation_process()

View File

@ -46,7 +46,7 @@
</p> </p>
<p> <p>
{% picto_from_name "calendar" %} {% 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 %} {% include "agenda_culturel/date-times-inc.html" with event=event %}
</p> </p>
</header> </header>

View File

@ -1,10 +1,10 @@
{% load utils_extra %} {% load utils_extra %}
{{ event.start_day|date|frdate }} {{ 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 }} {{ event.start_time }}
{% endif %} {% endif %}
{% if event.end_day %} {% if event.end_day and event.end_day != event.start_day %}
au {% if event.end_day %}{{ event.end_day|date|frdate }}{% endif %} au {% if event.end_day and event.end_day != event.start_day %}{{ event.end_day|date|frdate }}{% endif %}
{% endif %} {% endif %}
{% if event.end_time %} {% if not event.end_day|date|frdate %}jusqu'à{% endif %} {{ event.end_time }}{% endif %} {% if event.end_time %} {% if not event.end_day|date|frdate or event.end_day == event.start_day %}jusqu'à{% endif %} {{ event.end_time }}{% endif %}

View File

@ -7,7 +7,7 @@
<a href="{{ event.get_absolute_url }}"> <a href="{{ event.get_absolute_url }}">
{% if event.title_hl %}{{ event.title_hl | safe }}{% else %}{{ event.title }}{% endif %}</a></p> {% if event.title_hl %}{{ event.title_hl | safe }}{% else %}{{ event.title }}{% endif %}</a></p>
<p class="subentry-search">{% picto_from_name "calendar" %} <p class="subentry-search">{% 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 %} {% include "agenda_culturel/date-times-inc.html" with event=event %}
</header> </header>
<p class="subentry-search"></p> <p class="subentry-search"></p>

View File

@ -36,7 +36,7 @@
{% if event|need_complete_display:True %}<p> {% if event|need_complete_display:True %}<p>
{% picto_from_name "calendar" %} {% picto_from_name "calendar" %}
<em>{% if event.end_day %}Cet événement dure du {% else %}Cet événement a lieu le{% endif %} <em>{% 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 %} {% include "agenda_culturel/date-times-inc.html" with event=event %}
</em></p> </em></p>
{% endif %} {% endif %}

View File

@ -24,7 +24,7 @@
{% if event|need_complete_display:False %}<p> {% if event|need_complete_display:False %}<p>
{% picto_from_name "calendar" %} {% picto_from_name "calendar" %}
<em>{% if event.end_day %}Cet événement dure du {% else %}Cet événement a lieu le{% endif %} <em>{% 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 %} {% include "agenda_culturel/date-times-inc.html" with event=event %}
</em></p> </em></p>
{% endif %} {% endif %}

View File

@ -19,7 +19,7 @@
</p> </p>
<p> <p>
{% picto_from_name "calendar" %} {% 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 %} {% include "agenda_culturel/date-times-inc.html" with event=event %}
</p> </p>
</header> </header>

View File

@ -11,7 +11,7 @@
<h1>{{ event|picto_status }} {{ event.title }}</h1> <h1>{{ event|picto_status }} {{ event.title }}</h1>
<p> <p>
{% picto_from_name "calendar" %} {% 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 %} {% include "agenda_culturel/date-times-inc.html" with event=event %}
</p> </p>
<p> <p>