'
+ else:
+ result += '"
+
+ return mark_safe(result)
+
+
+ def get_selected_events_id(self, key):
+ value = self.cleaned_data.get(key)
+ if not key in self.fields:
+ return None
+ else:
+ if isinstance(value, list):
+ return [auc.rfind(v[-1]) for v in value]
+ else:
+ return auc.rfind(value[-1])
diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py
index e920bea..f7eb095 100644
--- a/src/agenda_culturel/models.py
+++ b/src/agenda_culturel/models.py
@@ -134,7 +134,8 @@ class DuplicatedEvents(models.Model):
def get_item_comparion(self, attr):
values = [getattr(e, attr) for e in self.get_duplicated()]
- if isinstance(values[0], list):
+
+ if len([x for x in [isinstance(i, list) for i in values] if x is True]) > 0:
hashable_values = "; ".join([str(v) for v in values])
else:
hashable_values = values
@@ -144,7 +145,7 @@ class DuplicatedEvents(models.Model):
return { "similar": False, "key": attr, "values": values }
def get_items_comparison(self):
- return [self.get_item_comparion(e) for e in Event.data_fields() + ["local_image"]]
+ return [self.get_item_comparion(e) for e in Event.data_fields(all=True)]
class Event(models.Model):
@@ -274,6 +275,11 @@ class Event(models.Model):
# if the download is ok, then create the corresponding file object
self.local_image = File(name=basename, file=open(tmpfile, "rb"))
+ def set_skip_duplicate_check(self):
+ self.skip_duplicate_check = True
+
+ def is_skip_duplicate_check(self):
+ return hasattr(self, "skip_duplicate_check")
def is_in_importation_process(self):
return hasattr(self, "in_importation_process")
@@ -302,7 +308,7 @@ class Event(models.Model):
# return a copy of the current object for each recurrence between first an last date (included)
def get_recurrences_between(self, firstdate, lastdate):
- if self.recurrences is None:
+ if not self.has_recurrences():
return [self]
else:
result = []
@@ -330,8 +336,7 @@ class Event(models.Model):
etime = time.fromisoformat(self.end_time) if isinstance(self.end_time, str) else time() if self.end_time is None else self.end_time
self.recurrence_dtstart = datetime.combine(sday, stime)
- # TODO: see https://forge.chapril.org/jmtrivial/agenda_culturel/issues/65
- if self.recurrences is None or len(self.recurrences.rrules) == 0:
+ if not self.has_recurrences():
if self.end_day is None:
self.dtend = None
else:
@@ -353,8 +358,6 @@ class Event(models.Model):
def prepare_save(self):
self.update_modification_dates()
- # TODO: update recurrences.dtstart et recurrences.dtend
-
self.update_recurrence_dtstartend()
# if the image is defined but not locally downloaded
@@ -366,8 +369,8 @@ class Event(models.Model):
self.prepare_save()
- # check for similar events if no duplicated is known
- if self.possibly_duplicated is None:
+ # check for similar events if no duplicated is known only if the event is created
+ if self.pk is None and self.possibly_duplicated is None and not self.is_skip_duplicate_check():
# and if this is not an importation process
if not self.is_in_importation_process():
similar_events = self.find_similar_events()
@@ -376,8 +379,9 @@ class Event(models.Model):
if len(similar_events) != 0:
self.set_possibly_duplicated(similar_events)
- elif self.possibly_duplicated is not None and self.possibly_duplicated.nb_duplicated() == 1:
- # delete duplicated group if it's only with one element
+
+ # delete duplicated group if it's only with one element
+ if self.possibly_duplicated is not None and self.possibly_duplicated.nb_duplicated() == 1:
self.possibly_duplicated.delete()
self.possibly_duplicated = None
@@ -386,8 +390,6 @@ class Event(models.Model):
def from_structure(event_structure, import_source = None):
- if event_structure["title"].endswith("ole"):
- logger.warning("on choope {}".format(event_structure))
if "category" in event_structure and event_structure["category"] is not None:
event_structure["category"] = Category.objects.get(name=event_structure["category"])
@@ -480,32 +482,45 @@ class Event(models.Model):
def set_possibly_duplicated(self, events):
+
# get existing groups
groups = list(set([e.possibly_duplicated for e in events] + [self.possibly_duplicated]))
groups = [g for g in groups if g is not None]
+
# do we have to create a new group?
if len(groups) == 0:
group = DuplicatedEvents.objects.create()
- logger.warning("set possibly duplicated 0 {}".format(group))
else:
# otherwise merge existing groups
group = DuplicatedEvents.merge_groups(groups)
- logger.warning("set possibly duplicated not 0 {}".format(group))
group.save()
+
# set the possibly duplicated group for the current object
self.possibly_duplicated = group
# and for the other events
for e in events:
e.possibly_duplicated = group
- # finally save the other events
- Event.objects.bulk_update(events, fields=["possibly_duplicated"])
+
+ # finally update all events (including current)
+ Event.objects.bulk_update(events + [self], fields=["possibly_duplicated"])
- def data_fields():
- return ["title", "location", "start_day", "start_time", "end_day", "end_time", "description", "image", "image_alt", "reference_urls", "recurrences"]
+ def data_fields(all=False):
+ if all:
+ result = ["category"]
+ else:
+ result = []
+
+ result += ["title", "location", "start_day", "start_time", "end_day", "end_time", "description", "image"]
+ if all:
+ result += ["local_image"]
+ result += ["image_alt", "reference_urls", "recurrences"]
+ if all:
+ result += ["tags"]
+ return result
def same_event_by_data(self, other):
for attr in Event.data_fields():
diff --git a/src/agenda_culturel/templates/agenda_culturel/duplicates.html b/src/agenda_culturel/templates/agenda_culturel/duplicates.html
index 4ae958f..7582450 100644
--- a/src/agenda_culturel/templates/agenda_culturel/duplicates.html
+++ b/src/agenda_culturel/templates/agenda_culturel/duplicates.html
@@ -20,7 +20,7 @@
{% for obj in paginator_filter %}
{% with obj.get_duplicated as events %}
- Possible duplication : {{ events|length }} événements le {{ events.0.start_day }}
+ Possible duplication : {{ events|length }} événements le {{ events.0.start_day }}
{% for e in events %}
diff --git a/src/agenda_culturel/templates/agenda_culturel/fix_duplicate.html b/src/agenda_culturel/templates/agenda_culturel/fix_duplicate.html
index c447bf8..589900a 100644
--- a/src/agenda_culturel/templates/agenda_culturel/fix_duplicate.html
+++ b/src/agenda_culturel/templates/agenda_culturel/fix_duplicate.html
@@ -16,14 +16,36 @@
Corriger des événements possiblement dupliqués
Les événements ci-dessous ont été détectés ou signalés comme possiblement dupliqué.
Les éléments qui diffèrent ont été dupliqués et mis en évidence.
+
+ {% if form %}
+
Choisissez dans la liste ci-dessous l'action que vous voulez réaliser. À noter que
+ s'il y a plus de deux événements, toutes les possibilités ne sont pas disponibles, et
+ il vous faudra peut-être réaliser certaines opérations à la main.
Pour chacun des champs non identiques, choisissez la version qui vous convient pour créer un événement
+ résultat de la fusion. Les événements source seront déplacés dans la corbeille.