From fae4dbbbf2b5eab4516bdf8e84aafdd2d36f8a8f Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Wed, 30 Oct 2024 14:25:21 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20du=20processus=20de=20cat?= =?UTF-8?q?=C3=A9gorisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index aba6d32..9dc456f 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -1730,18 +1730,22 @@ def apply_categorisation_rules(request): else: # first we check if events are not correctly categorised to_categorise = [] - for e in Event.objects.filter(start_day__gte=datetime.now()).exclude(category=Category.get_default_category_id()): + for e in Event.objects.filter(start_day__gte=datetime.now()).exclude(category=Category.get_default_category_id()).exclude(category=None): c = CategorisationRule.get_category_from_rules(e) if c and c != e.category: to_categorise.append((e, c)) # then we apply rules on events without category nb = 0 - for e in Event.objects.filter(start_day__gte=datetime.now()).filter(category=Category.get_default_category_id()): + to_save = [] + for e in Event.objects.filter(start_day__gte=datetime.now()).filter(Q(category=Category.get_default_category_id()) | Q(category=None)): success = CategorisationRule.apply_rules(e) if success: nb += 1 - e.save() + to_save.append(e) + + if nb != 0: + Event.objects.bulk_update(to_save, fields=["category"]) # set messages if nb != 0: