1 from collections import defaultdict
2 from django import template
3 from django.utils.datastructures import SortedDict
4 from ..models import Lesson, Section
5 from curriculum.models import Level, CurriculumCourse
6 from librarian.dcparser import WLURI, Person
8 register = template.Library()
11 @register.inclusion_tag("catalogue/snippets/carousel.html")
12 def catalogue_carousel():
14 "object_list": Section.objects.all()
17 @register.inclusion_tag("catalogue/snippets/levels_main.html")
18 def catalogue_levels_main():
19 object_list = Level.objects.exclude(lesson=None)
20 c = object_list.count()
22 'object_list': object_list,
23 #'section_width': (700 - 20 * (c - 1)) / c,
24 'section_width': (700 - 20 * 2) / 3
28 @register.inclusion_tag("catalogue/snippets/level_box.html")
32 course = SortedDict(),
35 by_course = defaultdict(lambda: defaultdict(list))
37 lesson_lists = [alist for alist in [
38 list(level.lesson_set.exclude(type='appendix').order_by('section__order', 'order')),
39 list(level.lessonstub_set.all())
43 min_index, min_list = min(enumerate(lesson_lists), key=lambda x: x[1][0].order)
44 lesson = min_list.pop(0)
46 lesson_lists.pop(min_index)
48 if lesson.type == 'course':
49 if lesson.section not in lessons['course']:
50 lessons['course'][lesson.section] = []
51 lessons['course'][lesson.section].append(lesson)
52 elif lesson.type.startswith('added'): continue
54 lessons[lesson.type].append(lesson)
56 if hasattr(lesson, 'curriculum_courses'):
57 for course in lesson.curriculum_courses.all():
58 by_course[course][lesson.type].append(lesson)
60 courses = [(course, by_course[course]) for course in
61 CurriculumCourse.objects.filter(lesson__level=level).distinct()]
64 if level.slug == 'liceum':
67 'title': u'Edukacja filmowa',
69 Lesson.objects.get(slug=s) for s in [
70 'film-co-to-wlasciwie-jest',
71 'scenariusz-scenopis-i-srodki-realizacyjne',
72 'kompozycja-obrazu-filmowego',
73 'praca-kamery-kadr-kat',
74 'montaz-materialu-filmowego',
75 'swiatlo-i-dzwiek-w-filmie',
76 'scenografia-charakteryzacja-kostiumy-i-aktorzy',
77 'narracja-w-filmie-tekst-i-fabula',
83 'title': u'Edukacja varsavianistyczna',
85 Lesson.objects.get(slug=s) for s in
87 czego-prus-w-lalce-o-zydach-nie-powiedzial
88 jak-zmienila-sie-warszawa-o-dworcu-dawniej-i-dzis
92 sladami-zydow-w-warszawie
93 tajemnice-palacu-saskiego
94 warszawa-przedwojenne-miasto-neonow
96 ziemianska-jako-soczewka-swiata-lat-miedzywojennych
109 @register.inclusion_tag("catalogue/snippets/lesson_nav.html")
110 def lesson_nav(lesson):
111 if lesson.type == 'course':
112 root = lesson.section
113 siblings = Lesson.objects.filter(type='course', level=lesson.level, section=root)
114 elif lesson.type == 'appendix':
116 siblings = Lesson.objects.filter(type=lesson.type)
117 elif lesson.type == 'added':
120 Lesson.objects.get(slug=s) for s in [
121 'film-co-to-wlasciwie-jest',
122 'scenariusz-scenopis-i-srodki-realizacyjne',
123 'kompozycja-obrazu-filmowego',
124 'praca-kamery-kadr-kat',
125 'montaz-materialu-filmowego',
126 'swiatlo-i-dzwiek-w-filmie',
127 'scenografia-charakteryzacja-kostiumy-i-aktorzy',
128 'narracja-w-filmie-tekst-i-fabula',
133 siblings = Lesson.objects.filter(type=lesson.type, level=lesson.level)
137 "siblings": siblings,
140 @register.inclusion_tag("catalogue/snippets/lesson_link.html")
141 def lesson_link(uri):
143 return {'lesson': Lesson.objects.get(slug=WLURI(uri).slug)}
144 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
155 @register.inclusion_tag('catalogue/latest_blog_posts.html')
156 def latest_blog_posts(feed_url, posts_to_show=5):
158 feed = feedparser.parse(str(feed_url))
160 for i in range(posts_to_show):
161 pub_date = feed['entries'][i].updated_parsed
162 published = datetime.date(pub_date[0], pub_date[1], pub_date[2] )
164 'title': feed['entries'][i].title,
165 'summary': feed['entries'][i].summary,
166 'link': feed['entries'][i].link,
169 return {'posts': posts}