1 # -*- coding: utf-8 -*-
2 from django import template
3 from django.utils.datastructures import SortedDict
4 from ..models import Competence, Curriculum, CurriculumCourse
5 from catalogue.models import Lesson
7 register = template.Library()
10 @register.inclusion_tag("curriculum/snippets/competence.html")
11 def competence(texts, level):
13 comps = [Competence.from_text(text) for text in texts]
16 return {'texts': texts}
23 @register.inclusion_tag("curriculum/snippets/curriculum.html")
24 def curriculum(identifiers):
26 currs = [Curriculum.objects.get(identifier__iexact=identifier.replace(' ', ''))
27 for identifier in identifiers]
28 except Curriculum.DoesNotExist:
29 return {'identifiers': identifiers}
31 currset = SortedDict()
33 k = curr.course, curr.level
35 currset[k] = SortedDict()
36 typename = Curriculum.TYPES[curr.type]
37 if typename not in currset[k]:
38 currset[k][typename] = []
39 currset[k][typename].append(curr)
47 def url_for_level(comp, level):
49 return comp.url_for_level(level)
52 return comp.get_absolute_url()
55 @register.inclusion_tag("curriculum/snippets/course_box.html")
56 def course_box(course):
57 lessons = SortedDict()
58 for lesson in course.lesson_set.all():
59 if lesson.level not in lessons:
60 newdict = SortedDict()
61 newdict['synthetic'] = []
62 newdict['course'] = []
63 lessons[lesson.level] = newdict
64 if lesson.type not in lessons[lesson.level]:
65 lessons[lesson.level][lesson.type] = []
66 lessons[lesson.level][lesson.type].append(lesson)
73 @register.inclusion_tag("curriculum/snippets/course_boxes.html")
75 return {'object_list': CurriculumCourse.objects.all()}
78 @register.inclusion_tag("curriculum/snippets/course_boxes_toc.html")
79 def course_boxes_toc(accusative=False):
82 lessons = Lesson.curriculum_courses.through.objects\
83 .select_related('lesson__level', 'curriculumcourse')\
84 .order_by('lesson__level', 'curriculumcourse')
86 level, course = l.lesson.level, l.curriculumcourse
87 if (level, course) == last:
90 object_list.append((level, []))
91 object_list[-1][1].append(course)
92 last = (level, course)
94 'object_list': object_list,
95 'accusative': accusative,