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, new=False):
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.verbose
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)
50 def url_for_level(comp, level):
52 return comp.url_for_level(level)
55 return comp.get_absolute_url()
58 @register.inclusion_tag("curriculum/snippets/course_box.html")
59 def course_box(course):
60 lessons = SortedDict()
61 for lesson in course.lesson_set.all():
62 if lesson.level not in lessons:
63 newdict = SortedDict()
64 newdict['synthetic'] = []
65 newdict['course'] = []
66 lessons[lesson.level] = newdict
67 if lesson.type not in lessons[lesson.level]:
68 lessons[lesson.level][lesson.type] = []
69 lessons[lesson.level][lesson.type].append(lesson)
76 @register.inclusion_tag("curriculum/snippets/course_boxes.html")
78 return {'object_list': CurriculumCourse.objects.all()}
81 @register.inclusion_tag("curriculum/snippets/course_boxes_toc.html")
82 def course_boxes_toc(accusative=False):
85 lessons = Lesson.curriculum_courses.through.objects\
86 .select_related('lesson__level', 'curriculumcourse')\
87 .order_by('lesson__level', 'curriculumcourse')
89 level, course = l.lesson.level, l.curriculumcourse
90 if (level, course) == last:
93 object_list.append((level, []))
94 object_list[-1][1].append(course)
95 last = (level, course)
97 'object_list': object_list,
98 'accusative': accusative,