On renomme le champ pour une meilleure compréhension
This commit is contained in:
parent
b8236f8816
commit
72242713eb
@ -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:
|
||||
|
@ -77,7 +77,7 @@ class EventForm(ModelForm):
|
||||
class Meta:
|
||||
model = Event
|
||||
exclude = [
|
||||
"possibly_duplicated",
|
||||
"other_versions",
|
||||
"imported_date",
|
||||
"modified_date",
|
||||
"moderated_date",
|
||||
|
@ -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',
|
||||
),
|
||||
]
|
@ -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):
|
||||
|
@ -84,12 +84,12 @@
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
</article>
|
||||
{% 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 %}
|
||||
<article>
|
||||
<header>
|
||||
{% if event.possibly_duplicated.representative %}
|
||||
{% if event.other_versions.representative %}
|
||||
<h2>Sources multiples</h2>
|
||||
<p class="remarque">L'événement affiché a également été trouvé à partir
|
||||
{% if poss_dup.count == 1 %}
|
||||
@ -119,7 +119,7 @@
|
||||
</nav>
|
||||
{% if user.is_authenticated %}
|
||||
<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>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
@ -18,19 +18,19 @@
|
||||
{% picto_from_name "map-pin" %}
|
||||
{% include "agenda_culturel/event-location-inc.html" with event=event %}
|
||||
</p>
|
||||
{% 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 %}
|
||||
<p class="remarque">
|
||||
{% if event.possibly_duplicated.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 %},
|
||||
{% if event.other_versions.representative %}
|
||||
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 %}
|
||||
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 %}
|
||||
et vous consultez l'import principal
|
||||
{% endif %}
|
||||
{% 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 %}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user