1 from django import template
2 from django.utils.datastructures import SortedDict
3 from ..models import Competence, Curriculum, CurriculumCourse
5 register = template.Library()
8 @register.inclusion_tag("curriculum/snippets/competence.html")
9 def competence(texts, level):
11 comps = [Competence.from_text(text) for text in texts]
13 return {'texts': texts}
19 @register.inclusion_tag("curriculum/snippets/curriculum.html")
20 def curriculum(identifiers):
22 currs = [Curriculum.objects.get(identifier=identifier)
23 for identifier in identifiers]
24 except Curriculum.DoesNotExist:
25 return {'identifiers': identifiers}
27 currset = SortedDict()
29 k = curr.course, curr.level
31 currset[k] = SortedDict()
32 typename = Curriculum.TYPES[curr.type]
33 if typename not in currset[k]:
34 currset[k][typename] = []
35 currset[k][typename].append(curr)
43 def url_for_level(comp, level):
45 return comp.url_for_level(level)
47 return comp.get_absolute_url()
50 @register.inclusion_tag("curriculum/snippets/course_box.html")
51 def course_box(course):
52 lessons = SortedDict()
53 for lesson in course.lesson_set.all():
54 if lesson.level not in lessons:
55 newdict = SortedDict()
56 newdict['synthetic'] = []
57 newdict['course'] = []
58 lessons[lesson.level] = newdict
59 if lesson.type not in lessons[lesson.level]:
60 lessons[lesson.level][lesson.type] = []
61 lessons[lesson.level][lesson.type].append(lesson)
66 @register.inclusion_tag("curriculum/snippets/course_boxes.html")
68 return {'object_list': CurriculumCourse.objects.all()}
70 @register.inclusion_tag("curriculum/snippets/course_boxes_toc.html")
71 def course_boxes_toc(accusative=False):
73 'object_list': CurriculumCourse.objects.all(),
74 'accusative': accusative,