On renomme le champ pour une meilleure compréhension

This commit is contained in:
Jean-Marie Favreau 2024-11-08 09:32:10 +01:00
parent b8236f8816
commit 72242713eb
7 changed files with 65 additions and 42 deletions

View File

@ -222,7 +222,7 @@ class CalendarList:
qs = self.filter.qs qs = self.filter.qs
if self.ignore_dup: 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()) 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()) lastdatetime = timezone.make_aware(datetime.combine(self.c_lastdate, time.max), timezone.get_default_timezone())
self.events = qs.filter( self.events = qs.filter(
@ -234,7 +234,7 @@ class CalendarList:
| Q(recurrence_dtend__lt=startdatetime) | 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()) firstdate = datetime.fromordinal(self.c_firstdate.toordinal())
if firstdate.tzinfo is None or firstdate.tzinfo.utcoffset(firstdate) is None: if firstdate.tzinfo is None or firstdate.tzinfo.utcoffset(firstdate) is None:

View File

@ -77,7 +77,7 @@ class EventForm(ModelForm):
class Meta: class Meta:
model = Event model = Event
exclude = [ exclude = [
"possibly_duplicated", "other_versions",
"imported_date", "imported_date",
"modified_date", "modified_date",
"moderated_date", "moderated_date",

View File

@ -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',
),
]

View File

@ -234,7 +234,7 @@ class DuplicatedEvents(models.Model):
# for all objects associated to this group # for all objects associated to this group
for e in self.event_set.all(): for e in self.event_set.all():
# change their group membership # change their group membership
e.possibly_duplicated = other e.other_versions = other
# save them # save them
e.save() e.save()
other.save() other.save()
@ -535,9 +535,9 @@ class Event(models.Model):
null=True, null=True,
) )
possibly_duplicated = models.ForeignKey( other_versions = models.ForeignKey(
DuplicatedEvents, DuplicatedEvents,
verbose_name=_("Possibly duplicated"), verbose_name=_("Other versions"),
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
null=True, null=True,
blank=True, blank=True,
@ -563,7 +563,7 @@ class Event(models.Model):
last = self.get_consolidated_end_day() last = self.get_consolidated_end_day()
ignore_dup = None ignore_dup = None
if remove_same_dup: if remove_same_dup:
ignore_dup = self.possibly_duplicated ignore_dup = self.other_versions
calendar = CalendarList(first, last, exact=True, ignore_dup=ignore_dup) 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()] 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() return Event.objects.filter(status=Event.STATUS.DRAFT).count()
def get_qs_events_with_unkwnon_place(): 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): def download_image(self):
# first download file # 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 # check for similar events if no duplicated is known only if the event is created
if ( if (
self.pk is None self.pk is None
and self.possibly_duplicated is None and self.other_versions is None
and not self.is_skip_duplicate_check() and not self.is_skip_duplicate_check()
): ):
# and if this is not an importation process # 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 it exists similar events, add this relation to the event
if len(similar_events) != 0: 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 # delete duplicated group if it's only with one element
if ( if (
self.possibly_duplicated is not None self.other_versions is not None
and self.possibly_duplicated.nb_duplicated() == 1 and self.other_versions.nb_duplicated() == 1
): ):
self.possibly_duplicated.delete() self.other_versions.delete()
self.possibly_duplicated = None self.other_versions = None
super().save(*args, **kwargs) super().save(*args, **kwargs)
@ -989,16 +989,16 @@ class Event(models.Model):
return True return True
return False return False
def get_possibly_duplicated(self): def get_other_versions(self):
if self.possibly_duplicated is None: if self.other_versions is None:
return [] return []
else: else:
return Event.objects.filter( return Event.objects.filter(
possibly_duplicated=self.possibly_duplicated other_versions=self.other_versions
).exclude(pk=self.pk) ).exclude(pk=self.pk)
def masked(self): 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): def get_comparison(events, all=True):
result = [] result = []
@ -1023,10 +1023,10 @@ class Event(models.Model):
return False return False
return True return True
def set_possibly_duplicated(self, events): def set_other_versions(self, events):
# get existing groups # get existing groups
groups = list( 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] groups = [g for g in groups if g is not None]
@ -1039,15 +1039,15 @@ class Event(models.Model):
group.save() group.save()
# set the possibly duplicated group for the current object # set the possibly duplicated group for the current object
self.possibly_duplicated = group self.other_versions = group
# and for the other events # and for the other events
for e in events: for e in events:
e.possibly_duplicated = group e.other_versions = group
# finally update all events (including current if already created) # finally update all events (including current if already created)
elist = list(events) + ([self] if self.pk is not None else []) 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): def data_fields(all=False, local_img=True, exact_location=True):
if all: if all:
@ -1184,7 +1184,7 @@ class Event(models.Model):
to_update.append(same_imported) to_update.append(same_imported)
else: else:
# otherwise, the new event possibly a duplication of the remaining others. # 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 # it will be imported
to_import.append(event) to_import.append(event)
else: else:
@ -1203,7 +1203,7 @@ class Event(models.Model):
to_update.append(same_events[0]) to_update.append(same_events[0])
else: else:
# the event is possibly a duplication of the others # 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) to_import.append(event)
else: else:
# import this new event # import this new event
@ -1283,7 +1283,7 @@ class Event(models.Model):
if e != self if e != self
and self.is_concurrent_event(e, day) and self.is_concurrent_event(e, day)
and e.status == Event.STATUS.PUBLISHED 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): def is_concurrent_event(self, e, day):

View File

@ -84,12 +84,12 @@
{% endwith %} {% endwith %}
{% endwith %} {% endwith %}
</article> </article>
{% if event.possibly_duplicated %} {% if event.other_versions %}
{% with poss_dup=event.get_possibly_duplicated|only_allowed:user.is_authenticated %} {% with poss_dup=event.get_other_versions|only_allowed:user.is_authenticated %}
{% if poss_dup.count > 0 %} {% if poss_dup.count > 0 %}
<article> <article>
<header> <header>
{% if event.possibly_duplicated.representative %} {% if event.other_versions.representative %}
<h2>Sources multiples</h2> <h2>Sources multiples</h2>
<p class="remarque">L'événement affiché a également été trouvé à partir <p class="remarque">L'événement affiché a également été trouvé à partir
{% if poss_dup.count == 1 %} {% if poss_dup.count == 1 %}
@ -119,7 +119,7 @@
</nav> </nav>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<footer> <footer>
<a role="button" href="{% url 'fix_duplicate' event.possibly_duplicated.pk %}">Corriger {% picto_from_name "tool" %}</a> <a role="button" href="{% url 'fix_duplicate' event.other_versions.pk %}">Corriger {% picto_from_name "tool" %}</a>
</footer> </footer>
{% endif %} {% endif %}
{% endif %} {% endif %}

View File

@ -18,19 +18,19 @@
{% picto_from_name "map-pin" %} {% picto_from_name "map-pin" %}
{% include "agenda_culturel/event-location-inc.html" with event=event %} {% include "agenda_culturel/event-location-inc.html" with event=event %}
</p> </p>
{% if event.possibly_duplicated %} {% if event.other_versions %}
{% with poss_dup=event.get_possibly_duplicated|only_allowed:user.is_authenticated %} {% with poss_dup=event.get_other_versions|only_allowed:user.is_authenticated %}
{% if poss_dup.count > 0 %} {% if poss_dup.count > 0 %}
<p class="remarque"> <p class="remarque">
{% if event.possibly_duplicated.representative %} {% if event.other_versions.representative %}
cet événement a été {% if user.is_authenticated %}<a href="{{ event.possibly_duplicated.get_absolute_url }}">importé plusieurs fois</a>{% else %}importé plusieurs fois{% endif %}, cet événement a été {% if user.is_authenticated %}<a href="{{ event.other_versions.get_absolute_url }}">importé plusieurs fois</a>{% else %}importé plusieurs fois{% endif %},
{% if event.masked %} {% if event.masked %}
vous pouvez <a href="{{ event.possibly_duplicated.get_one_event.get_absolute_url }}">consulter l'import principal</a> vous pouvez <a href="{{ event.other_versions.get_one_event.get_absolute_url }}">consulter l'import principal</a>
{% else %} {% else %}
et vous consultez l'import principal et vous consultez l'import principal
{% endif %} {% endif %}
{% else %} {% else %}
cet événement a probablement été {% if user.is_authenticated %}<a href="{{ event.possibly_duplicated.get_absolute_url }}">importé plusieurs fois</a>{% else %}importé plusieurs fois{% endif %} cet événement a probablement été {% if user.is_authenticated %}<a href="{{ event.other_versions.get_absolute_url }}">importé plusieurs fois</a>{% else %}importé plusieurs fois{% endif %}
{% endif %} {% endif %}
</p> </p>
{% endif %} {% endif %}

View File

@ -1462,7 +1462,7 @@ def merge_duplicate(request, pk):
# create a new event that merge the selected events # create a new event that merge the selected events
new_event = Event(**new_event_data) new_event = Event(**new_event_data)
new_event.status = Event.STATUS.PUBLISHED new_event.status = Event.STATUS.PUBLISHED
new_event.possibly_duplicated = edup new_event.other_versions = edup
edup.fix(new_event) edup.fix(new_event)
messages.info(request, _("Creation of a merged event has been successfully completed.")) 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()) return HttpResponseRedirect(edup.get_absolute_url())
elif form.is_action_remove(): elif form.is_action_remove():
event = form.get_selected_event(edup) event = form.get_selected_event(edup)
event.possibly_duplicated = None event.other_versions = None
if edup.representative == event: if edup.representative == event:
edup.representative = None edup.representative = None
event.save() event.save()
@ -1603,8 +1603,8 @@ def set_duplicate(request, year, month, day, pk):
for e in cday.get_events() for e in cday.get_events()
if e != event if e != event
and ( and (
event.possibly_duplicated is None event.other_versions is None
or event.possibly_duplicated != e.possibly_duplicated 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) form = SelectEventInList(request.POST, events=others)
if form.is_valid(): if form.is_valid():
selected = [o for o in others if o.pk == int(form.cleaned_data["event"])] 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() event.save()
if request.user.is_authenticated: if request.user.is_authenticated:
messages.success(request, _("The event was successfully duplicated.")) messages.success(request, _("The event was successfully duplicated."))
return HttpResponseRedirect( return HttpResponseRedirect(
reverse_lazy("view_duplicate", args=[event.possibly_duplicated.pk]) reverse_lazy("view_duplicate", args=[event.other_versions.pk])
) )
else: else:
messages.info( messages.info(