X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/3e55a1e4c5f489fab91c977a6b20e94867bb8245..f0f57cf9afe75ef139ed295e784fb8ae27351ebd:/catalogue/templatetags/catalogue_tags.py diff --git a/catalogue/templatetags/catalogue_tags.py b/catalogue/templatetags/catalogue_tags.py index 23ce402..a8d69e6 100755 --- a/catalogue/templatetags/catalogue_tags.py +++ b/catalogue/templatetags/catalogue_tags.py @@ -1,14 +1,19 @@ from django import template from django.utils.datastructures import SortedDict from ..models import Lesson, Section +from librarian.dcparser import WLURI, Person register = template.Library() @register.inclusion_tag("catalogue/snippets/carousel.html") def catalogue_carousel(): - return { - } + lessons_count = Lesson.objects.filter(type__in=('course', 'synthetic')).count() + if 1 < lessons_count % 10 < 5 and lessons_count / 10 % 10 != 1: + lessons_desc = u'kompletne lekcje' + else: + lessons_desc = u'kompletnych lekcji' + return locals() @register.inclusion_tag("catalogue/snippets/section_buttons.html") def catalogue_section_buttons(): @@ -16,15 +21,19 @@ def catalogue_section_buttons(): "object_list": Section.objects.all() } -@register.inclusion_tag("catalogue/snippets/chosen_topics.html") -def catalogue_chosen_topics(): - return { - } - @register.inclusion_tag("catalogue/snippets/section_box.html") def section_box(section): lessons = SortedDict() - for lesson in section.lesson_set.all(): + lesson_lists = [alist for alist in [ + list(section.lesson_set.all()), + list(section.lessonstub_set.all()) + ] if alist] + while lesson_lists: + min_index, min_list = min(enumerate(lesson_lists), key=lambda x: x[1][0].order) + lesson = min_list.pop(0) + if not min_list: + lesson_lists.pop(min_index) + if lesson.level not in lessons: newdict = SortedDict() newdict['synthetic'] = [] @@ -34,6 +43,7 @@ def section_box(section): lessons[lesson.level][lesson.type] = [] lessons[lesson.level][lesson.type].append(lesson) return { + "section": section, "lessons": lessons, } @@ -41,19 +51,29 @@ def section_box(section): def lesson_nav(lesson): if lesson.type == 'course': root = lesson.section - siblings = root.lesson_set.filter(type='course') + siblings = Lesson.objects.filter(type='course', level=lesson.level, section=root) + mark_level = False + link_other_level = True else: root = None siblings = Lesson.objects.filter(type=lesson.type) + mark_level = link_other_level = lesson.type == 'course' return { "lesson": lesson, "root": root, "siblings": siblings, + "mark_level": mark_level } +@register.inclusion_tag("catalogue/snippets/lesson_link.html") +def lesson_link(uri): + try: + return {'lesson': Lesson.objects.get(slug=WLURI(uri).slug)} + except Lesson.DoesNotExist: + return {} + @register.filter def person_list(persons): - from librarian.dcparser import Person return u", ".join(Person.from_text(p).readable() for p in persons)