X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/6c7e3b7d082affb3d779049d5311eb5775de65dd..fd65827f7d34921b927dfd735099b0690aa3a2df:/catalogue/templatetags/catalogue_tags.py?ds=sidebyside diff --git a/catalogue/templatetags/catalogue_tags.py b/catalogue/templatetags/catalogue_tags.py index 7003dfe..eecf9dc 100755 --- a/catalogue/templatetags/catalogue_tags.py +++ b/catalogue/templatetags/catalogue_tags.py @@ -1,6 +1,8 @@ +from collections import defaultdict from django import template from django.utils.datastructures import SortedDict from ..models import Lesson, Section +from curriculum.models import Level, CurriculumCourse from librarian.dcparser import WLURI, Person register = template.Library() @@ -8,34 +10,100 @@ register = template.Library() @register.inclusion_tag("catalogue/snippets/carousel.html") def catalogue_carousel(): - 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(): return { "object_list": Section.objects.all() } -@register.inclusion_tag("catalogue/snippets/section_box.html") -def section_box(section): - lessons = SortedDict() - for lesson in section.lesson_set.all(): - if lesson.level not in lessons: - 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) +@register.inclusion_tag("catalogue/snippets/levels_main.html") +def catalogue_levels_main(): + object_list = Level.objects.exclude(lesson=None) + c = object_list.count() + return { + 'object_list': object_list, + #'section_width': (700 - 20 * (c - 1)) / c, + 'section_width': (700 - 20 * 2) / 3 + } + + +@register.inclusion_tag("catalogue/snippets/level_box.html") +def level_box(level): + lessons = dict( + synthetic = [], + course = SortedDict(), + project = [], + ) + by_course = defaultdict(lambda: defaultdict(list)) + + lesson_lists = [alist for alist in [ + list(level.lesson_set.exclude(type='appendix').order_by('section__order', 'order')), + list(level.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.type == 'course': + if lesson.section not in lessons['course']: + lessons['course'][lesson.section] = [] + lessons['course'][lesson.section].append(lesson) + elif lesson.type.startswith('added'): continue + else: + lessons[lesson.type].append(lesson) + + if hasattr(lesson, 'curriculum_courses'): + for course in lesson.curriculum_courses.all(): + by_course[course][lesson.type].append(lesson) + + courses = [(course, by_course[course]) for course in + CurriculumCourse.objects.filter(lesson__level=level).distinct()] + + added = [] + if level.slug == 'liceum': + added.append({ + 'slug': 'filmowa', + 'title': u'Edukacja filmowa', + 'lessons': [ + Lesson.objects.get(slug=s) for s in [ +'film-co-to-wlasciwie-jest', +'scenariusz-scenopis-i-srodki-realizacyjne', +'kompozycja-obrazu-filmowego', +'praca-kamery-kadr-kat', +'montaz-materialu-filmowego', +'swiatlo-i-dzwiek-w-filmie', +'scenografia-charakteryzacja-kostiumy-i-aktorzy', +'narracja-w-filmie-tekst-i-fabula', + ] + ], + }) + added.append({ + 'slug': 'varsaviana', + 'title': u'Edukacja varsavianistyczna', + 'lessons': [ + Lesson.objects.get(slug=s) for s in +''' +czego-prus-w-lalce-o-zydach-nie-powiedzial +jak-zmienila-sie-warszawa-o-dworcu-dawniej-i-dzis +o-gwarze-praskiej +poznaj-i-pokaz-prage +praga-trzech-religii +sladami-zydow-w-warszawie +tajemnice-palacu-saskiego +warszawa-przedwojenne-miasto-neonow +warszawski-barok +ziemianska-jako-soczewka-swiata-lat-miedzywojennych +'''.strip().split() + ], + }) + + return { - "section": section, + "level": level, "lessons": lessons, + "courses": courses, + "added": added, } @register.inclusion_tag("catalogue/snippets/lesson_nav.html") @@ -43,16 +111,30 @@ def lesson_nav(lesson): if lesson.type == 'course': root = lesson.section siblings = Lesson.objects.filter(type='course', level=lesson.level, section=root) - mark_level = False - else: + elif lesson.type == 'appendix': root = None siblings = Lesson.objects.filter(type=lesson.type) - mark_level = True + elif lesson.type == 'added': + root = None + siblings = [ + Lesson.objects.get(slug=s) for s in [ +'film-co-to-wlasciwie-jest', +'scenariusz-scenopis-i-srodki-realizacyjne', +'kompozycja-obrazu-filmowego', +'praca-kamery-kadr-kat', +'montaz-materialu-filmowego', +'swiatlo-i-dzwiek-w-filmie', +'scenografia-charakteryzacja-kostiumy-i-aktorzy', +'narracja-w-filmie-tekst-i-fabula', + ] + ] + else: + root = None + siblings = Lesson.objects.filter(type=lesson.type, level=lesson.level) return { "lesson": lesson, "root": root, "siblings": siblings, - "mark_level": mark_level } @register.inclusion_tag("catalogue/snippets/lesson_link.html")