correction de l'application des règles

This commit is contained in:
Jean-Marie Favreau 2024-04-22 12:09:56 +02:00
parent d2ca848412
commit 0e5a3d4435

View File

@ -836,12 +836,12 @@ class CategorisationRule(models.Model):
category = models.ForeignKey(Category, verbose_name=_('Category'), help_text=_('Category applied to the event'), on_delete=models.CASCADE) category = models.ForeignKey(Category, verbose_name=_('Category'), help_text=_('Category applied to the event'), on_delete=models.CASCADE)
description_contains = models.CharField(verbose_name=_('Contained in the description'), help_text=_('Text contained in the description'), max_length=512, blank=True, null=True)
desc_exact = models.BooleanField(verbose_name=_('Exact description extract'), help_text=_("If checked, the extract will be searched for in the description using the exact form (capitals, accents)."), default=False)
title_contains = models.CharField(verbose_name=_('Contained in the title'), help_text=_('Text contained in the event title'), max_length=512, blank=True, null=True) title_contains = models.CharField(verbose_name=_('Contained in the title'), help_text=_('Text contained in the event title'), max_length=512, blank=True, null=True)
title_exact = models.BooleanField(verbose_name=_('Exact title extract'), help_text=_("If checked, the extract will be searched for in the title using the exact form (capitals, accents)."), default=False) title_exact = models.BooleanField(verbose_name=_('Exact title extract'), help_text=_("If checked, the extract will be searched for in the title using the exact form (capitals, accents)."), default=False)
description_contains = models.CharField(verbose_name=_('Contained in the description'), help_text=_('Text contained in the description'), max_length=512, blank=True, null=True)
desc_exact = models.BooleanField(verbose_name=_('Exact description extract'), help_text=_("If checked, the extract will be searched for in the description using the exact form (capitals, accents)."), default=False)
location_contains = models.CharField(verbose_name=_('Contained in the location'), help_text=_('Text contained in the event location'), max_length=512, blank=True, null=True) location_contains = models.CharField(verbose_name=_('Contained in the location'), help_text=_('Text contained in the event location'), max_length=512, blank=True, null=True)
loc_exact = models.BooleanField(verbose_name=_('Exact location extract'), help_text=_("If checked, the extract will be searched for in the location using the exact form (capitals, accents)."), default=False) loc_exact = models.BooleanField(verbose_name=_('Exact location extract'), help_text=_("If checked, the extract will be searched for in the location using the exact form (capitals, accents)."), default=False)
@ -873,9 +873,8 @@ class CategorisationRule(models.Model):
def match(self, event): def match(self, event):
result = False
if self.description_contains: if self.description_contains and self.description_contains != "":
if self.desc_exact: if self.desc_exact:
result = self.description_contains in event.description result = self.description_contains in event.description
else: else:
@ -883,27 +882,23 @@ class CategorisationRule(models.Model):
if not result: if not result:
return False return False
if self.title_contains: if self.title_contains and self.title_contains != "":
if self.title_exact: if self.title_exact:
t_result = self.title_contains in event.title result = self.title_contains in event.title
else: else:
t_result = remove_accents(self.title_contains).lower() in remove_accents(event.title).lower() result = remove_accents(self.title_contains).lower() in remove_accents(event.title).lower()
if result and not t_result: if not result:
return False return False
result = t_result
if self.location_contains: if self.location_contains and self.location_contains != "":
if self.loc_exact: if self.loc_exact:
l_result = self.location_contains in event.location result = self.location_contains in event.location
else: else:
l_result = remove_accents(self.location_contains).lower() in remove_accents(event.location).lower() result = remove_accents(self.location_contains).lower() in remove_accents(event.location).lower()
if not result:
if result and not l_result:
return False return False
result = l_result
return True
return result
class ModerationQuestion(models.Model): class ModerationQuestion(models.Model):