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,
27 @register.inclusion_tag("catalogue/snippets/level_box.html")
31 course = SortedDict(),
34 by_course = defaultdict(lambda: defaultdict(list))
36 lesson_lists = [alist for alist in [
37 list(level.lesson_set.exclude(type='appendix').order_by('section__order', 'order')),
38 list(level.lessonstub_set.all())
42 min_index, min_list = min(enumerate(lesson_lists), key=lambda x: x[1][0].order)
43 lesson = min_list.pop(0)
45 lesson_lists.pop(min_index)
47 if lesson.type == 'course':
48 if lesson.section not in lessons['course']:
49 lessons['course'][lesson.section] = []
50 lessons['course'][lesson.section].append(lesson)
51 elif lesson.type == 'added': continue
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]) for course in
60 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',
88 @register.inclusion_tag("catalogue/snippets/lesson_nav.html")
89 def lesson_nav(lesson):
90 if lesson.type == 'course':
92 siblings = Lesson.objects.filter(type='course', level=lesson.level, section=root)
93 elif lesson.type == 'appendix':
95 siblings = Lesson.objects.filter(type=lesson.type)
96 elif lesson.type == 'added':
99 Lesson.objects.get(slug=s) for s in [
100 'film-co-to-wlasciwie-jest',
101 'scenariusz-scenopis-i-srodki-realizacyjne',
102 'kompozycja-obrazu-filmowego',
103 'praca-kamery-kadr-kat',
104 'montaz-materialu-filmowego',
105 'swiatlo-i-dzwiek-w-filmie',
106 'scenografia-charakteryzacja-kostiumy-i-aktorzy',
107 'narracja-w-filmie-tekst-i-fabula',
112 siblings = Lesson.objects.filter(type=lesson.type, level=lesson.level)
116 "siblings": siblings,
119 @register.inclusion_tag("catalogue/snippets/lesson_link.html")
120 def lesson_link(uri):
122 return {'lesson': Lesson.objects.get(slug=WLURI(uri).slug)}
123 except Lesson.DoesNotExist:
127 def person_list(persons):
128 return u", ".join(Person.from_text(p).readable() for p in persons)
131 # FIXME: Move to fnpdjango
134 @register.inclusion_tag('catalogue/latest_blog_posts.html')
135 def latest_blog_posts(feed_url, posts_to_show=5):
137 feed = feedparser.parse(str(feed_url))
139 for i in range(posts_to_show):
140 pub_date = feed['entries'][i].updated_parsed
141 published = datetime.date(pub_date[0], pub_date[1], pub_date[2] )
143 'title': feed['entries'][i].title,
144 'summary': feed['entries'][i].summary,
145 'link': feed['entries'][i].link,
148 return {'posts': posts}