1 from django import template
2 from django.utils.datastructures import SortedDict
3 from ..models import Competence, Curriculum, CurriculumCourse
4 from catalogue.models import Lesson
6 register = template.Library()
9 @register.inclusion_tag("curriculum/snippets/competence.html")
10 def competence(texts, level):
12 comps = [Competence.from_text(text) for text in texts]
14 return {'texts': texts}
20 @register.inclusion_tag("curriculum/snippets/curriculum.html")
21 def curriculum(identifiers):
23 currs = [Curriculum.objects.get(identifier__iexact=identifier.replace(' ', ''))
24 for identifier in identifiers]
25 except Curriculum.DoesNotExist:
26 return {'identifiers': identifiers}
28 currset = SortedDict()
30 k = curr.course, curr.level
32 currset[k] = SortedDict()
33 typename = Curriculum.TYPES[curr.type]
34 if typename not in currset[k]:
35 currset[k][typename] = []
36 currset[k][typename].append(curr)
44 def url_for_level(comp, level):
46 return comp.url_for_level(level)
48 return comp.get_absolute_url()
51 @register.inclusion_tag("curriculum/snippets/course_box.html")
52 def course_box(course):
53 lessons = SortedDict()
54 for lesson in course.lesson_set.all():
55 if lesson.level not in lessons:
56 newdict = SortedDict()
57 newdict['synthetic'] = []
58 newdict['course'] = []
59 lessons[lesson.level] = newdict
60 if lesson.type not in lessons[lesson.level]:
61 lessons[lesson.level][lesson.type] = []
62 lessons[lesson.level][lesson.type].append(lesson)
68 @register.inclusion_tag("curriculum/snippets/course_boxes.html")
70 return {'object_list': CurriculumCourse.objects.all()}
72 @register.inclusion_tag("curriculum/snippets/course_boxes_toc.html")
73 def course_boxes_toc(accusative=False):
76 for l in Lesson.curriculum_courses.through.objects.all().order_by(
77 'lesson__level', 'curriculumcourse'):
78 level, course = l.lesson.level, l.curriculumcourse
79 if (level, course) == last:
82 object_list.append((level, []))
83 object_list[-1][1].append(course)
84 last = (level, course)
86 'object_list': object_list,
87 'accusative': accusative,