From 4c5decd6825dc1865475a61da9188971ce15448d Mon Sep 17 00:00:00 2001
From: Jean-Marie Favreau
Date: Fri, 8 Nov 2024 23:12:15 +0100
Subject: [PATCH] =?UTF-8?q?Les=20=C3=A9v=C3=A9nements=20correspondant=20au?=
=?UTF-8?q?x=20sources=20ne=20sont=20pas=20=C3=A9ditables,=20on=20cr=C3=A9?=
=?UTF-8?q?=C3=A9=20un=20cl=C3=B4ne=20=C3=A0=20la=20place?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/agenda_culturel/forms.py | 7 +++-
src/agenda_culturel/models.py | 40 +++++++++++++++++--
.../agenda_culturel/duplicate-diff-inc.html | 5 ++-
.../agenda_culturel/edit-buttons-inc.html | 16 ++++++--
.../agenda_culturel/event-info-inc.html | 1 -
.../templates/agenda_culturel/event_form.html | 15 +++++--
.../templates/agenda_culturel/page-event.html | 8 ++--
.../single-event/event-single-inc.html | 17 +++++---
src/agenda_culturel/urls.py | 1 +
src/agenda_culturel/views.py | 23 +++++++++--
10 files changed, 107 insertions(+), 26 deletions(-)
diff --git a/src/agenda_culturel/forms.py b/src/agenda_culturel/forms.py
index 3504042..d5eccba 100644
--- a/src/agenda_culturel/forms.py
+++ b/src/agenda_culturel/forms.py
@@ -77,7 +77,6 @@ class EventForm(ModelForm):
class Meta:
model = Event
exclude = [
- "other_versions",
"imported_date",
"modified_date",
"moderated_date",
@@ -100,6 +99,7 @@ class EventForm(ModelForm):
"end_day": TextInput(attrs={"type": "date"}),
"end_time": TextInput(attrs={"type": "time"}),
"uuids": MultipleHiddenInput(),
+ "other_versions": HiddenInput(),
"import_sources": MultipleHiddenInput(),
"reference_urls": DynamicArrayWidgetURLs(),
"tags": DynamicArrayWidgetTags(),
@@ -107,12 +107,17 @@ class EventForm(ModelForm):
def __init__(self, *args, **kwargs):
is_authenticated = kwargs.pop("is_authenticated", False)
+ self.cloning = kwargs.pop("is_cloning", False)
super().__init__(*args, **kwargs)
if not is_authenticated:
del self.fields["status"]
self.fields['category'].queryset = self.fields['category'].queryset.order_by('name')
self.fields['category'].empty_label = None
self.fields['category'].initial = Category.get_default_category()
+ logger.warning("ça se passe là")
+
+ def is_clone_from_url(self):
+ return self.cloning
def clean_end_day(self):
start_day = self.cleaned_data.get("start_day")
diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py
index 5512533..be8de14 100644
--- a/src/agenda_culturel/models.py
+++ b/src/agenda_culturel/models.py
@@ -642,9 +642,34 @@ class Event(models.Model):
def modified(self):
return (
- not self.modified_date is None
+ not self.pure_import()
and (self.modified_date - self.created_date).total_seconds() > 1
)
+
+ def pure_import(self):
+ if self.imported_date is None:
+ return False
+ return self.modified_date is None or (self.modified_date - self.imported_date).total_seconds() <= 0
+
+
+ def get_local_version(self):
+ # a non-pure import is a local version
+ if not self.pure_import():
+ return self
+
+ # in case of non other version, return None
+ if self.other_versions is None:
+ return None
+
+ # otherwise check the representative version
+ if not self.other_versions.representative is None:
+ if self.other_versions.representative.modified():
+ return self.other_versions.representative
+
+ # finally, get the last modified version within the other versions
+ e = [e for e in self.other_versions.event_set.order_by("-modified_date") if e.modified]
+
+ return None if len(e) == 0 else e[0]
def nb_draft_events():
return Event.objects.filter(status=Event.STATUS.DRAFT).count()
@@ -834,11 +859,12 @@ class Event(models.Model):
if len(similar_events) != 0:
self.set_other_versions(similar_events)
- # delete duplicated group if it's only with one element
if (
+ self.pk and
self.other_versions is not None
and self.other_versions.nb_duplicated() == 1
):
+ logger.warning("le other est juste dans ", self.other_versions.event_set.all())
self.other_versions.delete()
self.other_versions = None
@@ -1003,6 +1029,14 @@ class Event(models.Model):
return True
return False
+ def get_other_not_trash_versions(self):
+ if self.other_versions is None:
+ return []
+ else:
+ return Event.objects.filter(
+ other_versions=self.other_versions
+ ).filter(~Q(status=Event.STATUS.TRASH)).exclude(pk=self.pk)
+
def get_other_versions(self):
if self.other_versions is None:
return []
@@ -1012,7 +1046,7 @@ class Event(models.Model):
).exclude(pk=self.pk)
def masked(self):
- return self.other_versions and self.other_versions.representative == self
+ return self.other_versions and self.other_versions.representative != self
def get_comparison(events, all=True):
result = []
diff --git a/src/agenda_culturel/templates/agenda_culturel/duplicate-diff-inc.html b/src/agenda_culturel/templates/agenda_culturel/duplicate-diff-inc.html
index 2c09214..f97f86d 100644
--- a/src/agenda_culturel/templates/agenda_culturel/duplicate-diff-inc.html
+++ b/src/agenda_culturel/templates/agenda_culturel/duplicate-diff-inc.html
@@ -9,10 +9,13 @@
- {{ e|picto_status }} {{ e.title }}
- - Masqué : {{ e.masked|yesno:"Oui,Non" }}
- Création : {{ e.created_date }}
- Dernière modification : {{ e.modified_date }}
{% if e.imported_date %}- Dernière importation : {{ e.imported_date }}
{% endif %}
+ - État :
+ {% if e.pure_import %}version fidèle à la source importée{% endif %}
+ {% if e.modified %}version modifiée localement{% endif %}
+
{% endfor %}
diff --git a/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html b/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html
index 0ea47ab..389eac5 100644
--- a/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html
+++ b/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html
@@ -1,13 +1,23 @@
{% load utils_extra %}
+
+{% if event.pure_import %}
+ {% with event.get_local_version as local %}
+ {% if local %}
+ voir la version locale {% picto_from_name "eye" %}
+ {% else %}
+ créer une copie locale {% picto_from_name "plus-circle" %}
+ {% endif %}
+ {% endwith %}
+{% else %}
+modifier {% picto_from_name "edit-3" %}
+{% endif %}
+
{% if event.is_updateable %}
Réimporter {% picto_from_name "download-cloud" %}
{% endif %}
-
-modifier {% picto_from_name "edit-3" %}
-
{% if event.status != "published" %}
publier {% picto_from_name "eye" %}
{% endif %}
diff --git a/src/agenda_culturel/templates/agenda_culturel/event-info-inc.html b/src/agenda_culturel/templates/agenda_culturel/event-info-inc.html
index 21c8cb9..fd968dc 100644
--- a/src/agenda_culturel/templates/agenda_culturel/event-info-inc.html
+++ b/src/agenda_culturel/templates/agenda_culturel/event-info-inc.html
@@ -5,7 +5,6 @@
{% if object.modified_date %}Dernière modification : {{ object.modified_date }}{% endif %}
{% if object.moderated_date %}Dernière modération : {{ object.moderated_date }}{% endif %}
{% if object.imported_date %}Dernière importation : {{ object.imported_date }}{% endif %}
- Masqué : {{ object.masked }}
{% if object.uuids %}
{% if object.uuids|length > 0 %}
UUIDs (identifiants uniques d'événements dans les sources) :
diff --git a/src/agenda_culturel/templates/agenda_culturel/event_form.html b/src/agenda_culturel/templates/agenda_culturel/event_form.html
index 06aeda7..ed5db02 100644
--- a/src/agenda_culturel/templates/agenda_culturel/event_form.html
+++ b/src/agenda_culturel/templates/agenda_culturel/event_form.html
@@ -3,8 +3,10 @@
{% block title %}{% block og_title %}
-{% if object %}
+{% if object %}{% if form.is_clone_from_url %}
+Création d'une copie de {% else %}
Édition de l'événement {{ object.title }} ({{ object.start_day }})
+{% endif %}
{% else %}
{% if from_import %}
Ajuster l'événement importé
@@ -40,13 +42,14 @@
{% block content %}
-
{% load static_content_extra %}
{% if object %}
- Édition de l'événement {{ object.title }} ({{ object.start_day }})
+ {% if form.is_clone_from_url %}
+ Création d'une copie de {% else %}
+ Édition de l'événement{% endif %} {{ object.title }} ({{ object.start_day }})
{% else %}
{% if from_import %}
Ajuster l'événement importé
@@ -58,7 +61,10 @@
-
+
{% if object %}
{% include "agenda_culturel/event-info-inc.html" %}
{% endif %}
diff --git a/src/agenda_culturel/templates/agenda_culturel/page-event.html b/src/agenda_culturel/templates/agenda_culturel/page-event.html
index 8cef71c..a00aa57 100644
--- a/src/agenda_culturel/templates/agenda_culturel/page-event.html
+++ b/src/agenda_culturel/templates/agenda_culturel/page-event.html
@@ -87,15 +87,15 @@
{% if event.other_versions %}
{% with poss_dup=event.get_other_versions|only_allowed:user.is_authenticated %}
{% if poss_dup.count > 0 %}
-
+
{% if event.other_versions.representative %}
Sources multiples
- L'événement affiché a également été trouvé à partir
+
L'événement affiché est également disponible
{% if poss_dup.count == 1 %}
- d'une autre source
+ dans une autre version
{% else %}
- d'autres sources
+ dans d'autres versions
{% endif %} :
{% else %}
Possibles doublons
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 434c632..6ac1063 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
@@ -19,18 +19,18 @@
{% include "agenda_culturel/event-location-inc.html" with event=event %}
{% if event.other_versions %}
- {% with poss_dup=event.get_other_versions|only_allowed:user.is_authenticated %}
+ {% with poss_dup=event.get_other_not_trash_versions|only_allowed:user.is_authenticated %}
{% if poss_dup.count > 0 %}
{% if event.other_versions.representative %}
- cet événement a été {% if user.is_authenticated %}importé plusieurs fois{% else %}importé plusieurs fois{% endif %},
+ cet événement existe en plusieurs versions,
{% if event.masked %}
- vous pouvez consulter l'import principal
+ vous pouvez consulter la version mise en avant
{% else %}
- et vous consultez l'import principal
+ et vous consultez la version mise en avant
{% endif %}
{% else %}
- cet événement a probablement été {% if user.is_authenticated %}importé plusieurs fois{% else %}importé plusieurs fois{% endif %}
+ cet événement existe probablement en plusieurs versions
{% endif %}
{% endif %}
@@ -83,9 +83,16 @@
{% if event.modified %}
— dernière modification : {{ event.modified_date }}
{% endif %}
+ {% if event.imported_date %}
+ — dernière importation : {{ event.imported_date }}
+ {% endif %}
{% if event.moderated_date %}
— dernière modération : {{ event.moderated_date }}
{% endif %}
+ {% if event.pure_import %}
+ — version importée
+ {% endif %}
+ {{ event.delai }}