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")
11 comps = [Competence.from_text(text) for text in texts]
13 return {'texts': texts}
18 @register.inclusion_tag("curriculum/snippets/curriculum.html")
19 def curriculum(identifiers):
21 currs = [Curriculum.objects.get(identifier=identifier)
22 for identifier in identifiers]
23 except Curriculum.DoesNotExist:
24 return {'identifiers': identifiers}
26 currset = SortedDict()
28 k = curr.course, curr.level
30 currset[k] = SortedDict()
31 typename = Curriculum.TYPES[curr.type]
32 if typename not in currset[k]:
33 currset[k][typename] = []
34 currset[k][typename].append(curr)
42 def url_for_level(comp, level):
44 return comp.for_level(level).get_absolute_url()
46 return comp.get_absolute_url()
49 @register.inclusion_tag("curriculum/snippets/course_box.html")
50 def course_box(course):
51 lessons = SortedDict()
52 for lesson in course.lesson_set.all():
53 if lesson.level not in lessons:
54 newdict = SortedDict()
55 newdict['synthetic'] = []
56 newdict['course'] = []
57 lessons[lesson.level] = newdict
58 if lesson.type not in lessons[lesson.level]:
59 lessons[lesson.level][lesson.type] = []
60 lessons[lesson.level][lesson.type].append(lesson)
65 @register.inclusion_tag("curriculum/snippets/course_boxes.html")
67 return {'object_list': CurriculumCourse.objects.all()}
69 @register.inclusion_tag("curriculum/snippets/course_boxes_toc.html")
70 def course_boxes_toc(accusative=False):
72 'object_list': CurriculumCourse.objects.all(),
73 'accusative': accusative,