amélioration de la mécanique de catégorisation
This commit is contained in:
parent
4d4bf65c0c
commit
c93805aa64
@ -642,14 +642,14 @@ class Event(models.Model):
|
|||||||
self.download_image()
|
self.download_image()
|
||||||
|
|
||||||
if self.is_in_importation_process():
|
if self.is_in_importation_process():
|
||||||
# try to detect category
|
|
||||||
CategorisationRule.apply_rules(self)
|
|
||||||
# try to detect location
|
# try to detect location
|
||||||
if not self.exact_location:
|
if not self.exact_location:
|
||||||
for p in Place.objects.all():
|
for p in Place.objects.all():
|
||||||
if p.match(self):
|
if p.match(self):
|
||||||
self.exact_location = p
|
self.exact_location = p
|
||||||
break
|
break
|
||||||
|
# try to detect category
|
||||||
|
CategorisationRule.apply_rules(self)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.prepare_save()
|
self.prepare_save()
|
||||||
@ -1438,6 +1438,15 @@ class CategorisationRule(models.Model):
|
|||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
place = models.ForeignKey(
|
||||||
|
Place,
|
||||||
|
verbose_name=_("Place"),
|
||||||
|
help_text=_("Location from place"),
|
||||||
|
null=True,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
blank=True,
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("Categorisation rule")
|
verbose_name = _("Categorisation rule")
|
||||||
verbose_name_plural = _("Categorisation rules")
|
verbose_name_plural = _("Categorisation rules")
|
||||||
@ -1497,6 +1506,11 @@ class CategorisationRule(models.Model):
|
|||||||
if not result:
|
if not result:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if self.place:
|
||||||
|
if not event.exact_location == self.place:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ from .models import (
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
|
from django.utils.timezone import datetime
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
@ -1519,14 +1520,14 @@ 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.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()):
|
||||||
c = CategorisationRule.match_rules(e)
|
c = CategorisationRule.match_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(category=Category.get_default_category_id()):
|
for e in Event.objects.filter(start_day__gte=datetime.now()).filter(category=Category.get_default_category_id()):
|
||||||
success = CategorisationRule.apply_rules(e)
|
success = CategorisationRule.apply_rules(e)
|
||||||
if success:
|
if success:
|
||||||
nb += 1
|
nb += 1
|
||||||
|
Loading…
Reference in New Issue
Block a user