Amélioration du processus de catégorisation
This commit is contained in:
parent
4f2af09464
commit
fae4dbbbf2
@ -1730,18 +1730,22 @@ def apply_categorisation_rules(request):
|
|||||||
else:
|
else:
|
||||||
# first we check if events are not correctly categorised
|
# first we check if events are not correctly categorised
|
||||||
to_categorise = []
|
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)
|
c = CategorisationRule.get_category_from_rules(e)
|
||||||
if c and c != e.category:
|
if c and c != e.category:
|
||||||
to_categorise.append((e, c))
|
to_categorise.append((e, c))
|
||||||
|
|
||||||
# then we apply rules on events without category
|
# then we apply rules on events without category
|
||||||
nb = 0
|
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)
|
success = CategorisationRule.apply_rules(e)
|
||||||
if success:
|
if success:
|
||||||
nb += 1
|
nb += 1
|
||||||
e.save()
|
to_save.append(e)
|
||||||
|
|
||||||
|
if nb != 0:
|
||||||
|
Event.objects.bulk_update(to_save, fields=["category"])
|
||||||
|
|
||||||
# set messages
|
# set messages
|
||||||
if nb != 0:
|
if nb != 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user