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):
25 # shouldn't be needed, but is
26 identifiers = [id for id in identifiers if id]
28 currs = [Curriculum.objects.get(identifier__iexact=identifier.replace(' ', ''))
29 for identifier in identifiers]
30 except Curriculum.DoesNotExist:
31 return {'identifiers': identifiers}
33 currset = SortedDict()
35 k = curr.course, curr.level
37 currset[k] = SortedDict()
38 typename = Curriculum.TYPES[curr.type]
39 if typename not in currset[k]:
40 currset[k][typename] = []
41 currset[k][typename].append(curr)
49 def url_for_level(comp, level):
51 return comp.url_for_level(level)
54 return comp.get_absolute_url()
57 @register.inclusion_tag("curriculum/snippets/course_box.html")
58 def course_box(course):
59 lessons = SortedDict()
60 for lesson in course.lesson_set.all():
61 if lesson.level not in lessons:
62 newdict = SortedDict()
63 newdict['synthetic'] = []
64 newdict['course'] = []
65 lessons[lesson.level] = newdict
66 if lesson.type not in lessons[lesson.level]:
67 lessons[lesson.level][lesson.type] = []
68 lessons[lesson.level][lesson.type].append(lesson)
75 @register.inclusion_tag("curriculum/snippets/course_boxes.html")
77 return {'object_list': CurriculumCourse.objects.all()}
80 @register.inclusion_tag("curriculum/snippets/course_boxes_toc.html")
81 def course_boxes_toc(accusative=False):
84 lessons = Lesson.curriculum_courses.through.objects\
85 .select_related('lesson__level', 'curriculumcourse')\
86 .order_by('lesson__level', 'curriculumcourse')
88 level, course = l.lesson.level, l.curriculumcourse
89 if (level, course) == last:
92 object_list.append((level, []))
93 object_list[-1][1].append(course)
94 last = (level, course)
96 'object_list': object_list,
97 'accusative': accusative,