suppression de duplicated events vides

This commit is contained in:
Jean-Marie Favreau 2024-04-28 12:19:50 +02:00
parent 59b093340d
commit 0f193ea902
2 changed files with 8 additions and 1 deletions

View File

@ -12,7 +12,7 @@ import os
from django.core.files import File
from django.utils import timezone
from django.contrib.postgres.search import TrigramSimilarity
from django.db.models import Q
from django.db.models import Q, Count
import recurrence.fields
import recurrence
import copy
@ -148,6 +148,11 @@ class DuplicatedEvents(models.Model):
def get_items_comparison(self):
return Event.get_comparison(self.get_duplicated())
def remove_singletons():
singletons = DuplicatedEvents.objects.annotate(nb_events=Count("event")).filter(nb_events__lte=1)
logger.warning("Removing: " + str(len(singletons)) + " empty or singleton duplicated")
singletons.delete()
class Place(models.Model):
name = models.CharField(verbose_name=_('Name'), help_text=_('Name of the place'))
address = models.CharField(verbose_name=_('Address'), help_text=_('Address of this place (without city name)'), blank=True, null=True)

View File

@ -872,6 +872,8 @@ class DuplicatedEventsUpdateView(LoginRequiredMixin, UpdateView):
@login_required(login_url="/accounts/login/")
@permission_required('agenda_culturel.view_duplicatedevents')
def duplicates(request):
DuplicatedEvents.remove_singletons()
paginator = Paginator(DuplicatedEvents.objects.all(), 10)
page = request.GET.get('page')