Add command to remove space from skill notation

This commit is contained in:
Gregory Trullemans 2022-10-13 22:11:12 +02:00
parent 4b320d3a7c
commit 58c5d83658
2 changed files with 33 additions and 9 deletions

View File

@ -13,7 +13,7 @@ from ultron.objective.models import Educative, PrerequisiteClosure
class Command(BaseCommand):
def handle(self, *args, **options):
educative_list = Educative.objects.all()
count = 0
for educative in educative_list:
updated = False
max_level = 0
@ -27,7 +27,7 @@ class Command(BaseCommand):
age_girl_without_help = 0
age_girl_chained = 0
age_girl_masterised = 0
count += 1
print(str(count) + ' - Traitement de ' + str(educative.long_label))
breadcrumb = educative.breadcrumb()
@ -56,7 +56,6 @@ class Command(BaseCommand):
for tree_path in tree:
tree_path.delete()
# Dans une condition pour espérer accélérer le traitement
if educative.level != max_level:
updated = True
educative.level = max_level
@ -65,7 +64,6 @@ class Command(BaseCommand):
updated = True
educative.rank = max_rank
# Age boy defining
if educative.age_boy_with_help < age_boy_with_help:
updated = True
educative.age_boy_with_help = age_boy_with_help
@ -82,7 +80,6 @@ class Command(BaseCommand):
updated = True
educative.age_boy_masterised = age_boy_masterised
# Age girl defined
if educative.age_girl_with_help < age_girl_with_help:
updated = True
educative.age_girl_with_help = age_girl_with_help

View File

@ -0,0 +1,27 @@
""" Retire les espaces contenu dans le champ "notation" et "simplified notation" de la class skill
dans le but de faciliter les recherches (skill_lookup).
"""
from django.core.management.base import BaseCommand
from ultron.objective.models import Skill
class Command(BaseCommand):
def handle(self, *args, **options):
skill_list = Skill.objects.all()
for skill in skill_list:
need_update = False
notation = skill.notation.replace(" ", "")
simplified_notation = skill.simplified_notation.replace(" ", "")
if notation != skill.notation:
need_update = True
skill.notation = notation
if simplified_notation != skill.simplified_notation:
need_update = True
skill.simplified_notation = simplified_notation
if need_update:
skill.save()