diff --git a/src/agenda_culturel/calendar.py b/src/agenda_culturel/calendar.py index 75fb3ce..99e094f 100644 --- a/src/agenda_culturel/calendar.py +++ b/src/agenda_culturel/calendar.py @@ -222,7 +222,7 @@ class CalendarList: qs = self.filter.qs if self.ignore_dup: - qs = qs.exclude(possibly_duplicated=self.ignore_dup) + qs = qs.exclude(other_versions=self.ignore_dup) startdatetime = timezone.make_aware(datetime.combine(self.c_firstdate, time.min), timezone.get_default_timezone()) lastdatetime = timezone.make_aware(datetime.combine(self.c_lastdate, time.max), timezone.get_default_timezone()) self.events = qs.filter( @@ -234,7 +234,7 @@ class CalendarList: | Q(recurrence_dtend__lt=startdatetime) ) ) - ).filter(Q(possibly_duplicated__isnull=True)|~Q(possibly_duplicated__representative=F('pk'))).order_by("start_time").prefetch_related("exact_location").prefetch_related("category") + ).filter(Q(other_versions__isnull=True)|~Q(other_versions__representative=F('pk'))).order_by("start_time").prefetch_related("exact_location").prefetch_related("category") firstdate = datetime.fromordinal(self.c_firstdate.toordinal()) if firstdate.tzinfo is None or firstdate.tzinfo.utcoffset(firstdate) is None: diff --git a/src/agenda_culturel/forms.py b/src/agenda_culturel/forms.py index f37b574..1525750 100644 --- a/src/agenda_culturel/forms.py +++ b/src/agenda_culturel/forms.py @@ -77,7 +77,7 @@ class EventForm(ModelForm): class Meta: model = Event exclude = [ - "possibly_duplicated", + "other_versions", "imported_date", "modified_date", "moderated_date", diff --git a/src/agenda_culturel/migrations/0105_remove_event_masked_remove_event_possibly_duplicated_and_more.py b/src/agenda_culturel/migrations/0105_remove_event_masked_remove_event_possibly_duplicated_and_more.py new file mode 100644 index 0000000..77ea905 --- /dev/null +++ b/src/agenda_culturel/migrations/0105_remove_event_masked_remove_event_possibly_duplicated_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.9 on 2024-11-08 08:30 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('agenda_culturel', '0104_remove_duplicatedevents_fixed'), + ] + + operations = [ + migrations.RemoveField( + model_name='event', + name='masked', + ), + migrations.RenameField( + model_name='event', + old_name='possibly_duplicated', + new_name='other_versions', + ), + ] diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index a497e65..2e150b7 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -234,7 +234,7 @@ class DuplicatedEvents(models.Model): # for all objects associated to this group for e in self.event_set.all(): # change their group membership - e.possibly_duplicated = other + e.other_versions = other # save them e.save() other.save() @@ -535,9 +535,9 @@ class Event(models.Model): null=True, ) - possibly_duplicated = models.ForeignKey( + other_versions = models.ForeignKey( DuplicatedEvents, - verbose_name=_("Possibly duplicated"), + verbose_name=_("Other versions"), on_delete=models.SET_NULL, null=True, blank=True, @@ -563,7 +563,7 @@ class Event(models.Model): last = self.get_consolidated_end_day() ignore_dup = None if remove_same_dup: - ignore_dup = self.possibly_duplicated + ignore_dup = self.other_versions calendar = CalendarList(first, last, exact=True, ignore_dup=ignore_dup) return [(len(d.events), d.date) for dstr, d in calendar.get_calendar_days().items()] @@ -636,7 +636,7 @@ class Event(models.Model): return Event.objects.filter(status=Event.STATUS.DRAFT).count() def get_qs_events_with_unkwnon_place(): - return Event.objects.filter(exact_location__isnull=True).filter(~Q(status=Event.STATUS.TRASH)).filter(Q(possibly_duplicated=None)|~Q(possibly_duplicated__representative=F('pk'))) + return Event.objects.filter(exact_location__isnull=True).filter(~Q(status=Event.STATUS.TRASH)).filter(Q(other_versions=None)|~Q(other_versions__representative=F('pk'))) def download_image(self): # first download file @@ -809,7 +809,7 @@ class Event(models.Model): # 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 self.other_versions is None and not self.is_skip_duplicate_check() ): # and if this is not an importation process @@ -818,15 +818,15 @@ class Event(models.Model): # if it exists similar events, add this relation to the event if len(similar_events) != 0: - self.set_possibly_duplicated(similar_events) + self.set_other_versions(similar_events) # 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.other_versions is not None + and self.other_versions.nb_duplicated() == 1 ): - self.possibly_duplicated.delete() - self.possibly_duplicated = None + self.other_versions.delete() + self.other_versions = None super().save(*args, **kwargs) @@ -989,16 +989,16 @@ class Event(models.Model): return True return False - def get_possibly_duplicated(self): - if self.possibly_duplicated is None: + def get_other_versions(self): + if self.other_versions is None: return [] else: return Event.objects.filter( - possibly_duplicated=self.possibly_duplicated + other_versions=self.other_versions ).exclude(pk=self.pk) def masked(self): - return self.possibly_duplicated and self.possibly_duplicated.representative == self + return self.other_versions and self.other_versions.representative == self def get_comparison(events, all=True): result = [] @@ -1023,10 +1023,10 @@ class Event(models.Model): return False return True - def set_possibly_duplicated(self, events): + def set_other_versions(self, events): # get existing groups groups = list( - set([e.possibly_duplicated for e in events] + [self.possibly_duplicated]) + set([e.other_versions for e in events] + [self.other_versions]) ) groups = [g for g in groups if g is not None] @@ -1039,15 +1039,15 @@ class Event(models.Model): group.save() # set the possibly duplicated group for the current object - self.possibly_duplicated = group + self.other_versions = group # and for the other events for e in events: - e.possibly_duplicated = group + e.other_versions = group # finally update all events (including current if already created) elist = list(events) + ([self] if self.pk is not None else []) - Event.objects.bulk_update(elist, fields=["possibly_duplicated"]) + Event.objects.bulk_update(elist, fields=["other_versions"]) def data_fields(all=False, local_img=True, exact_location=True): if all: @@ -1184,7 +1184,7 @@ class Event(models.Model): to_update.append(same_imported) else: # otherwise, the new event possibly a duplication of the remaining others. - event.set_possibly_duplicated(same_events) + event.set_other_versions(same_events) # it will be imported to_import.append(event) else: @@ -1203,7 +1203,7 @@ class Event(models.Model): to_update.append(same_events[0]) else: # the event is possibly a duplication of the others - event.set_possibly_duplicated(similar_events) + event.set_other_versions(similar_events) to_import.append(event) else: # import this new event @@ -1283,7 +1283,7 @@ class Event(models.Model): if e != self and self.is_concurrent_event(e, day) and e.status == Event.STATUS.PUBLISHED - and (e.possibly_duplicated is None or e.possibly_duplicated != self.possibly_duplicated) + and (e.other_versions is None or e.other_versions != self.other_versions) ] def is_concurrent_event(self, e, day): diff --git a/src/agenda_culturel/templates/agenda_culturel/page-event.html b/src/agenda_culturel/templates/agenda_culturel/page-event.html index b6f490e..3174d00 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page-event.html +++ b/src/agenda_culturel/templates/agenda_culturel/page-event.html @@ -84,12 +84,12 @@ {% endwith %} {% endwith %} - {% if event.possibly_duplicated %} - {% with poss_dup=event.get_possibly_duplicated|only_allowed:user.is_authenticated %} + {% if event.other_versions %} + {% with poss_dup=event.get_other_versions|only_allowed:user.is_authenticated %} {% if poss_dup.count > 0 %}
- {% if event.possibly_duplicated.representative %} + {% if event.other_versions.representative %}

Sources multiples

L'événement affiché a également été trouvé à partir {% if poss_dup.count == 1 %} @@ -119,7 +119,7 @@ {% if user.is_authenticated %}

{% endif %} {% endif %} 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 bda0ac2..434c632 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 @@ -18,19 +18,19 @@ {% picto_from_name "map-pin" %} {% include "agenda_culturel/event-location-inc.html" with event=event %}

- {% if event.possibly_duplicated %} - {% with poss_dup=event.get_possibly_duplicated|only_allowed:user.is_authenticated %} + {% if event.other_versions %} + {% with poss_dup=event.get_other_versions|only_allowed:user.is_authenticated %} {% if poss_dup.count > 0 %}

- {% if event.possibly_duplicated.representative %} - cet événement a été {% if user.is_authenticated %}importé plusieurs fois{% else %}importé plusieurs fois{% endif %}, + {% if event.other_versions.representative %} + cet événement a été {% if user.is_authenticated %}importé plusieurs fois{% else %}importé plusieurs fois{% endif %}, {% if event.masked %} - vous pouvez consulter l'import principal + vous pouvez consulter l'import principal {% else %} et vous consultez l'import principal {% endif %} {% else %} - cet événement a probablement été {% if user.is_authenticated %}importé plusieurs fois{% else %}importé plusieurs fois{% endif %} + cet événement a probablement été {% if user.is_authenticated %}importé plusieurs fois{% else %}importé plusieurs fois{% endif %} {% endif %}

{% endif %} diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 683a99d..2e195e4 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -1462,7 +1462,7 @@ def merge_duplicate(request, pk): # create a new event that merge the selected events new_event = Event(**new_event_data) new_event.status = Event.STATUS.PUBLISHED - new_event.possibly_duplicated = edup + new_event.other_versions = edup edup.fix(new_event) messages.info(request, _("Creation of a merged event has been successfully completed.")) @@ -1529,7 +1529,7 @@ def fix_duplicate(request, pk): return HttpResponseRedirect(edup.get_absolute_url()) elif form.is_action_remove(): event = form.get_selected_event(edup) - event.possibly_duplicated = None + event.other_versions = None if edup.representative == event: edup.representative = None event.save() @@ -1603,8 +1603,8 @@ def set_duplicate(request, year, month, day, pk): for e in cday.get_events() if e != event and ( - event.possibly_duplicated is None - or event.possibly_duplicated != e.possibly_duplicated + event.other_versions is None + or event.other_versions != e.other_versions ) ] @@ -1614,12 +1614,12 @@ def set_duplicate(request, year, month, day, pk): form = SelectEventInList(request.POST, events=others) if form.is_valid(): selected = [o for o in others if o.pk == int(form.cleaned_data["event"])] - event.set_possibly_duplicated(selected) + event.set_other_versions(selected) event.save() if request.user.is_authenticated: messages.success(request, _("The event was successfully duplicated.")) return HttpResponseRedirect( - reverse_lazy("view_duplicate", args=[event.possibly_duplicated.pk]) + reverse_lazy("view_duplicate", args=[event.other_versions.pk]) ) else: messages.info(