Refactoring

This commit is contained in:
Jean-Marie Favreau 2024-10-30 14:19:39 +01:00
parent 5f13e91267
commit 4f2af09464
2 changed files with 9 additions and 10 deletions

View File

@ -1632,14 +1632,13 @@ class CategorisationRule(models.Model):
# all rules are applied, starting from the first to the last
def apply_rules(event):
rules = CategorisationRule.objects.all().order_by("weight", "pk")
for rule in rules:
if rule.match(event):
event.category = rule.category
return 1
return 0
c = CategorisationRule.get_category_from_rules(event)
if c is None:
return 0
else:
event.category = c
return 1
def get_category_from_rules(event):
rules = CategorisationRule.objects.all().order_by("weight", "pk")

View File

@ -1749,14 +1749,14 @@ def apply_categorisation_rules(request):
messages.success(
request,
_(
"The rules were successfully applied and 1 event was categorised."
"The rules were successfully applied and 1 event with default category was categorised."
),
)
else:
messages.success(
request,
_(
"The rules were successfully applied and {} events were categorised."
"The rules were successfully applied and {} events with default category were categorised."
).format(nb),
)
else: