diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index a74eecf..e920bea 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -107,6 +107,9 @@ class DuplicatedEvents(models.Model): def nb_duplicated(self): return Event.objects.filter(possibly_duplicated=self).count() + def get_duplicated(self): + return Event.objects.filter(possibly_duplicated=self) + def merge_into(self, other): # for all objects associated to this group for e in Event.objects.filter(possibly_duplicated=self): @@ -129,6 +132,19 @@ class DuplicatedEvents(models.Model): return result + def get_item_comparion(self, attr): + values = [getattr(e, attr) for e in self.get_duplicated()] + if isinstance(values[0], list): + hashable_values = "; ".join([str(v) for v in values]) + else: + hashable_values = values + if len(set(hashable_values)) == 1: + return { "similar": True, "key": attr, "values": values[0] } + else: + 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"]] class Event(models.Model): @@ -489,7 +505,7 @@ class Event(models.Model): def data_fields(): - return ["title", "location", "start_day", "start_time", "end_day", "end_time", "description", "image", "image_alt", "image_alt", "reference_urls", "recurrences"] + return ["title", "location", "start_day", "start_time", "end_day", "end_time", "description", "image", "image_alt", "reference_urls", "recurrences"] def same_event_by_data(self, other): for attr in Event.data_fields(): diff --git a/src/agenda_culturel/static/style.scss b/src/agenda_culturel/static/style.scss index 9b6464c..6590345 100644 --- a/src/agenda_culturel/static/style.scss +++ b/src/agenda_culturel/static/style.scss @@ -627,9 +627,9 @@ aside nav a.selected { background: var(--primary-focus); } aside nav a.badge { - float: right; z-index: 1; margin-top: -2em; + float: right; } .body-fixed { @@ -720,7 +720,50 @@ aside nav a.badge { } article article { - margin-top: 3em; - margin-bottom: 3em; + margin: 3em 0.5em; padding: 0.6em 0.2em; +} + + +.badge-circle { + display: block; + float: left; + width: 2.5em; + height: 2.5em; + line-height: 2.5em; + text-align: center; + border-radius: 50%; + color: var(--secondary-inverse); + background: $primary-500; +} + + +.entete-badge { + grid-template-columns: 2.5em repeat(auto-fit, minmax(0%, 1fr)); + + .badge-large { + @extend .badge-circle; + font-size: 140%; + } + li { + list-style-type: none; + } +} + +.comparison-item { + margin: 0.4em; + .duplicated { + padding: 0.5em; + background: rgba(255, 0, 76, 0.1); + border-radius: 0.5em; + } + + .badge-small { + @extend .badge-circle; + font-size: 70%; + width: 2em; + height: 2em; + line-height: 2em; + margin-right: 1em; + } } \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/duplicates.html b/src/agenda_culturel/templates/agenda_culturel/duplicates.html new file mode 100644 index 0000000..4ae958f --- /dev/null +++ b/src/agenda_culturel/templates/agenda_culturel/duplicates.html @@ -0,0 +1,62 @@ +{% extends "agenda_culturel/page.html" %} + +{% load utils_extra %} + +{% block title %}Événements possiblement dupliqués{% endblock %} + +{% load cat_extra %} +{% block entete_header %} + {% css_categories %} +{% endblock %} + +{% block content %} +
+
+
+

Événements possiblement dupliqués

+
+ +
+{% for obj in paginator_filter %} + {% with obj.get_duplicated as events %} + + {% endwith %} +{% endfor %} +
+ +
+ +{% include "agenda_culturel/side-nav.html" with current="duplicates" %} +
+ +{% endblock %} \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/fix_duplicate.html b/src/agenda_culturel/templates/agenda_culturel/fix_duplicate.html new file mode 100644 index 0000000..c447bf8 --- /dev/null +++ b/src/agenda_culturel/templates/agenda_culturel/fix_duplicate.html @@ -0,0 +1,48 @@ +{% extends "agenda_culturel/page.html" %} + +{% load utils_extra %} +{% load event_extra %} + +{% block title %}Événements possiblement dupliqués{% endblock %} + +{% load cat_extra %} +{% block entete_header %} + {% css_categories %} +{% endblock %} + +{% block content %} +
+
+

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.

+
+
+ {% for e in object.get_duplicated %} +
+
+ {{ forloop.counter }} +
+
    +
  • Création : {{ e.created_date }}
  • +
  • Dernière modification : {{ e.modified_date }}
  • + {% if e.imported_date %}
  • Dernière importation : {{ e.imported_date }}
  • {% endif %} +
+
+ {% endfor %} +
+ {% for e in object.get_items_comparison %} +

{% event_field_verbose_name e.key %}

+ {% if e.similar %} +
Identique : {% field_to_html e.values e.key %}
+ {% else %} +
+ {% for i in e.values %} +
{{ forloop.counter }}
{% field_to_html i e.key %}
+ {% endfor %} +
+ {% endif %} + {% endfor %} +
+{% endblock %} + diff --git a/src/agenda_culturel/templates/agenda_culturel/page-event.html b/src/agenda_culturel/templates/agenda_culturel/page-event.html index 2c5fdb6..d1ae9d4 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page-event.html +++ b/src/agenda_culturel/templates/agenda_culturel/page-event.html @@ -70,6 +70,11 @@ {% endfor %} + {% if user.is_authenticated %} + + {% endif %} {% endif %} diff --git a/src/agenda_culturel/templates/agenda_culturel/page.html b/src/agenda_culturel/templates/agenda_culturel/page.html index 241db77..e03f054 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page.html +++ b/src/agenda_culturel/templates/agenda_culturel/page.html @@ -25,6 +25,7 @@ {% load event_extra %} {% load contactmessages_extra %} {% load utils_extra %} +{% load duplicated_extra %}