suppression des non dupliqués
This commit is contained in:
parent
526e2d8d49
commit
9a7733566c
@ -151,10 +151,29 @@ class DuplicatedEvents(models.Model):
|
||||
def remove_singletons():
|
||||
singletons = DuplicatedEvents.objects.annotate(nb_events=Count("event")).filter(nb_events__lte=1)
|
||||
nb = len(singletons)
|
||||
if nb > 0:
|
||||
logger.warning("Removing: " + str(nb) + " empty or singleton duplicated")
|
||||
singletons.delete()
|
||||
return nb
|
||||
|
||||
def remove_similar_entries():
|
||||
to_be_removed = []
|
||||
duplicates = DuplicatedEvents.objects.all()
|
||||
for d in duplicates:
|
||||
comp = d.get_items_comparison()
|
||||
similar = len([c for c in comp if not c["similar"]]) > 0
|
||||
if similar:
|
||||
to_be_removed.append(d)
|
||||
|
||||
nb = len(to_be_removed)
|
||||
if nb > 0:
|
||||
logger.warning("Removing: " + str(nb) + " similar duplicated")
|
||||
for s in to_be_removed:
|
||||
s.delete()
|
||||
return nb
|
||||
|
||||
|
||||
|
||||
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)
|
||||
|
@ -873,8 +873,9 @@ class DuplicatedEventsUpdateView(LoginRequiredMixin, UpdateView):
|
||||
@permission_required('agenda_culturel.view_duplicatedevents')
|
||||
def duplicates(request):
|
||||
nb_removed = DuplicatedEvents.remove_singletons()
|
||||
if nb_removed:
|
||||
messages.success(request, _("Cleaning up duplicates: {} item(s) removed.").format(nb_removed))
|
||||
nb_similar = DuplicatedEvents.remove_similar_entries()
|
||||
if nb_removed > 0 or nb_similar > 0:
|
||||
messages.success(request, _("Cleaning up duplicates: {} item(s) removed.").format(nb_removed + nb_similar))
|
||||
|
||||
paginator = Paginator(DuplicatedEvents.objects.all(), 10)
|
||||
page = request.GET.get('page')
|
||||
|
Loading…
x
Reference in New Issue
Block a user