X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/e76fdcf2a2488b1787c74fe8dccfa38d7ac04c84..84ffd6f6aeef8c7898dfa9d9d97aa323647172b7:/catalogue/templatetags/catalogue_tags.py diff --git a/catalogue/templatetags/catalogue_tags.py b/catalogue/templatetags/catalogue_tags.py index 23a4066..23ce402 100755 --- a/catalogue/templatetags/catalogue_tags.py +++ b/catalogue/templatetags/catalogue_tags.py @@ -1,6 +1,6 @@ from django import template from django.utils.datastructures import SortedDict -from ..models import Section +from ..models import Lesson, Section register = template.Library() @@ -26,14 +26,36 @@ def section_box(section): lessons = SortedDict() for lesson in section.lesson_set.all(): if lesson.level not in lessons: - lessons[lesson.level] = SortedDict() - if lesson.depth not in lessons[lesson.level]: - lessons[lesson.level][lesson.depth] = [] - lessons[lesson.level][lesson.depth].append(lesson) + newdict = SortedDict() + newdict['synthetic'] = [] + newdict['course'] = [] + lessons[lesson.level] = newdict + if lesson.type not in lessons[lesson.level]: + lessons[lesson.level][lesson.type] = [] + lessons[lesson.level][lesson.type].append(lesson) return { "lessons": lessons, } +@register.inclusion_tag("catalogue/snippets/lesson_nav.html") +def lesson_nav(lesson): + if lesson.type == 'course': + root = lesson.section + siblings = root.lesson_set.filter(type='course') + else: + root = None + siblings = Lesson.objects.filter(type=lesson.type) + return { + "lesson": lesson, + "root": root, + "siblings": siblings, + } + +@register.filter +def person_list(persons): + from librarian.dcparser import Person + return u", ".join(Person.from_text(p).readable() for p in persons) + # FIXME: Move to fnpdjango import feedparser