From 58c5d83658c07361715d062c0dfcfea3028d7f24 Mon Sep 17 00:00:00 2001 From: Gregory Trullemans Date: Thu, 13 Oct 2022 22:11:12 +0200 Subject: [PATCH] Add command to remove space from skill notation --- ..._tree.py => rebuild_closure_table_tree.py} | 15 +++++------ .../remove_space_from_skill_notation.py | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) rename ultron/objective/management/commands/{rebuild_tree.py => rebuild_closure_table_tree.py} (94%) create mode 100644 ultron/objective/management/commands/remove_space_from_skill_notation.py diff --git a/ultron/objective/management/commands/rebuild_tree.py b/ultron/objective/management/commands/rebuild_closure_table_tree.py similarity index 94% rename from ultron/objective/management/commands/rebuild_tree.py rename to ultron/objective/management/commands/rebuild_closure_table_tree.py index db3f388cc3..3b8df80ca2 100644 --- a/ultron/objective/management/commands/rebuild_tree.py +++ b/ultron/objective/management/commands/rebuild_closure_table_tree.py @@ -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() @@ -49,14 +49,13 @@ class Command(BaseCommand): age_girl_without_help = max(age_girl_without_help, ancestor.age_girl_without_help) age_girl_chained = max(age_girl_chained, ancestor.age_girl_chained) age_girl_masterised = max(age_girl_masterised, ancestor.age_girl_masterised) - + if tree_path in tree: tree.remove(tree_path) - + 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 @@ -77,12 +75,11 @@ class Command(BaseCommand): if educative.age_boy_chained < age_boy_chained: updated = True educative.age_boy_chained = age_boy_chained - + if educative.age_boy_masterised < age_boy_masterised: 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 @@ -94,7 +91,7 @@ class Command(BaseCommand): if educative.age_girl_chained < age_girl_chained: updated = True educative.age_girl_chained = age_girl_chained - + if educative.age_girl_masterised < age_girl_masterised: updated = True educative.age_girl_masterised = age_girl_masterised diff --git a/ultron/objective/management/commands/remove_space_from_skill_notation.py b/ultron/objective/management/commands/remove_space_from_skill_notation.py new file mode 100644 index 0000000000..1d56832ec4 --- /dev/null +++ b/ultron/objective/management/commands/remove_space_from_skill_notation.py @@ -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()