1 # -*- coding: utf-8 -*-
2 from collections import defaultdict
3 from django import template
4 from django.utils.datastructures import SortedDict
5 from ..models import Lesson, Section
6 from curriculum.models import Level, CurriculumCourse
7 from librarian.dcparser import WLURI, Person
9 register = template.Library()
12 @register.inclusion_tag("catalogue/snippets/carousel.html")
13 def catalogue_carousel():
15 "object_list": Section.objects.all()
19 @register.inclusion_tag("catalogue/snippets/levels_main.html")
20 def catalogue_levels_main():
21 object_list = Level.objects.exclude(lesson=None)
22 c = object_list.count()
24 'object_list': object_list,
25 # 'section_width': (700 - 20 * (c - 1)) / c,
26 'section_width': (700 - 20 * 2) / 3
30 @register.inclusion_tag("catalogue/snippets/level_box.html")
32 lessons = {'synthetic': [], 'course': SortedDict(), 'project': []}
33 by_course = defaultdict(lambda: defaultdict(list))
35 lesson_lists = [alist for alist in [
36 list(level.lesson_set.exclude(type='appendix').order_by('section__order', 'order')),
37 list(level.lessonstub_set.all())
41 min_index, min_list = min(enumerate(lesson_lists), key=lambda x: x[1][0].order)
42 lesson = min_list.pop(0)
44 lesson_lists.pop(min_index)
46 if lesson.type == 'course':
47 if lesson.section not in lessons['course']:
48 lessons['course'][lesson.section] = []
49 lessons['course'][lesson.section].append(lesson)
50 elif lesson.type.startswith('added'):
53 lessons[lesson.type].append(lesson)
55 if hasattr(lesson, 'curriculum_courses'):
56 for course in lesson.curriculum_courses.all():
57 by_course[course][lesson.type].append(lesson)
59 courses = [(course, by_course[course])
60 for course in CurriculumCourse.objects.filter(lesson__level=level).distinct()]
63 if level.slug == 'liceum':
66 'title': u'Edukacja filmowa',
68 Lesson.objects.get(slug=s) for s in [
69 'film-co-to-wlasciwie-jest',
70 'scenariusz-scenopis-i-srodki-realizacyjne',
71 'kompozycja-obrazu-filmowego',
72 'praca-kamery-kadr-kat',
73 'montaz-materialu-filmowego',
74 'swiatlo-i-dzwiek-w-filmie',
75 'scenografia-charakteryzacja-kostiumy-i-aktorzy',
76 'narracja-w-filmie-tekst-i-fabula',
82 'title': u'Edukacja varsavianistyczna',
84 Lesson.objects.get(slug=s) for s in [
85 'czego-prus-w-lalce-o-zydach-nie-powiedzial',
86 'jak-zmienila-sie-warszawa-o-dworcu-dawniej-i-dzis',
88 'poznaj-i-pokaz-prage',
89 'praga-trzech-religii',
90 'sladami-zydow-w-warszawie',
91 'tajemnice-palacu-saskiego',
92 'warszawa-przedwojenne-miasto-neonow',
94 'ziemianska-jako-soczewka-swiata-lat-miedzywojennych',
107 @register.inclusion_tag("catalogue/snippets/lesson_nav.html")
108 def lesson_nav(lesson):
109 if lesson.type == 'course':
110 root = lesson.section
111 siblings = Lesson.objects.filter(type='course', level=lesson.level, section=root)
112 elif lesson.type == 'appendix':
114 siblings = Lesson.objects.filter(type=lesson.type)
115 elif lesson.type == 'added':
118 Lesson.objects.get(slug=s) for s in [
119 'film-co-to-wlasciwie-jest',
120 'scenariusz-scenopis-i-srodki-realizacyjne',
121 'kompozycja-obrazu-filmowego',
122 'praca-kamery-kadr-kat',
123 'montaz-materialu-filmowego',
124 'swiatlo-i-dzwiek-w-filmie',
125 'scenografia-charakteryzacja-kostiumy-i-aktorzy',
126 'narracja-w-filmie-tekst-i-fabula',
131 siblings = Lesson.objects.filter(type=lesson.type, level=lesson.level)
135 "siblings": siblings,
139 @register.inclusion_tag("catalogue/snippets/lesson_link.html")
140 def lesson_link(uri):
142 return {'lesson': Lesson.objects.get(slug=WLURI(uri).slug)}
143 except Lesson.DoesNotExist:
148 def person_list(persons):
149 return u", ".join(Person.from_text(p).readable() for p in persons)
152 # FIXME: Move to fnpdjango
157 @register.inclusion_tag('catalogue/latest_blog_posts.html')
158 def latest_blog_posts(feed_url, posts_to_show=5):
160 feed = feedparser.parse(str(feed_url))
162 for i in range(posts_to_show):
163 pub_date = feed['entries'][i].updated_parsed
164 published = datetime.date(pub_date[0], pub_date[1], pub_date[2])
166 'title': feed['entries'][i].title,
167 'summary': feed['entries'][i].summary,
168 'link': feed['entries'][i].link,
171 return {'posts': posts}