Remove unexpected indent
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Gregory Trullemans 2022-01-12 21:29:17 +01:00
parent d6c3df1c3b
commit 1146b97411
2 changed files with 45 additions and 45 deletions

View File

@ -1,44 +1,44 @@
"""This command manages Closure Tables implementation
It adds new levels and cleans links between Educatives.
This way, it's relatively easy to fetch an entire tree with just one tiny request.
"""
from django.core.management.base import BaseCommand
from ultron.objective.models import Educative, PrerequisiteClosure
class Command(BaseCommand):
def handle(self, *args, **options):
# educative_list = Educative.objects.all()
educative_list = [Educative.objects.get(pk=44)]
for educative in educative_list:
# print('__________________________________________________________________________')
# print('Traitement de ' + str(educative))
# breadcrumb = [node for node in educative.breadcrumb()]
breadcrumb = educative.breadcrumb()
for path in range(0, len(breadcrumb)):
# print(' ˪ ' + str(path + 1) + 'ème chemin')
tree = set(PrerequisiteClosure.objects.filter(descendant=educative, path=path))
# print(' ' + str(tree))
for position, ancestor in enumerate(breadcrumb[path]):
# print(' ˪ Traitement de ' + str(ancestor.long_label) + ' : ' + str(ancestor.long_label) + ' -> ' + str(educative.long_label) + ' | ' + str(position) + ' | ' + str(path))
tree_path, _ = PrerequisiteClosure.objects.get_or_create(
ancestor=ancestor, descendant=educative, level=position, path=path
)
# if _:
# print(' -> CREATION : ' + str(tree_path))
# else:
# print(' -> RECUPERATION : ' + str(tree_path))
if tree_path in tree:
tree.remove(tree_path)
for tree_path in tree:
# print(' DELETE : ' + str(tree_path))
tree_path.delete()
It adds new levels and cleans links between Educatives.
This way, it's relatively easy to fetch an entire tree with just one tiny request.
"""
from django.core.management.base import BaseCommand
from ultron.objective.models import Educative, PrerequisiteClosure
class Command(BaseCommand):
def handle(self, *args, **options):
# educative_list = Educative.objects.all()
educative_list = [Educative.objects.get(pk=44)]
for educative in educative_list:
# print('__________________________________________________________________________')
# print('Traitement de ' + str(educative))
# breadcrumb = [node for node in educative.breadcrumb()]
breadcrumb = educative.breadcrumb()
for path in range(0, len(breadcrumb)):
# print(' ˪ ' + str(path + 1) + 'ème chemin')
tree = set(PrerequisiteClosure.objects.filter(descendant=educative, path=path))
# print(' ' + str(tree))
for position, ancestor in enumerate(breadcrumb[path]):
# print(' ˪ Traitement de ' + str(ancestor.long_label) + ' : ' + str(ancestor.long_label) + ' -> ' + str(educative.long_label) + ' | ' + str(position) + ' | ' + str(path))
tree_path, _ = PrerequisiteClosure.objects.get_or_create(
ancestor=ancestor, descendant=educative, level=position, path=path
)
# if _:
# print(' -> CREATION : ' + str(tree_path))
# else:
# print(' -> RECUPERATION : ' + str(tree_path))
if tree_path in tree:
tree.remove(tree_path)
for tree_path in tree:
# print(' DELETE : ' + str(tree_path))
tree_path.delete()

View File

@ -76,8 +76,8 @@ def skill_tree(request, skill_id):
"""
skill = get_object_or_404(Skill, pk=skill_id)
print(skill)
skill_tree = PrerequisiteClosure.objects.filter(descendant=skill).order_by("path", "level")
print(skill_tree)
skill_breadcrumb = PrerequisiteClosure.objects.filter(descendant=skill).order_by("path", "level")
print(skill_breadcrumb)
context = {"skill": skill}
return render(request, "objectives/skills/tree.html", context)