diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index 126b49a..22cb6bc 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -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) - 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_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) 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): - result = False - if self.description_contains: + if self.description_contains and self.description_contains != "": if self.desc_exact: result = self.description_contains in event.description else: @@ -883,27 +882,23 @@ class CategorisationRule(models.Model): if not result: return False - if self.title_contains: + if self.title_contains and self.title_contains != "": if self.title_exact: - t_result = self.title_contains in event.title + result = self.title_contains in event.title else: - t_result = remove_accents(self.title_contains).lower() in remove_accents(event.title).lower() - if result and not t_result: + result = remove_accents(self.title_contains).lower() in remove_accents(event.title).lower() + if not result: return False - result = t_result - if self.location_contains: + if self.location_contains and self.location_contains != "": if self.loc_exact: - l_result = self.location_contains in event.location + result = self.location_contains in event.location else: - l_result = remove_accents(self.location_contains).lower() in remove_accents(event.location).lower() - - if result and not l_result: + result = remove_accents(self.location_contains).lower() in remove_accents(event.location).lower() + if not result: return False - result = l_result - - return result + return True class ModerationQuestion(models.Model):