1 from django import template
2 from django.utils.datastructures import SortedDict
3 from ..models import Lesson, Section
4 from librarian.dcparser import WLURI, Person
6 register = template.Library()
9 @register.inclusion_tag("catalogue/snippets/carousel.html")
10 def catalogue_carousel():
14 @register.inclusion_tag("catalogue/snippets/section_buttons.html")
15 def catalogue_section_buttons():
17 "object_list": Section.objects.all()
20 @register.inclusion_tag("catalogue/snippets/section_box.html")
21 def section_box(section):
22 lessons = SortedDict()
23 for lesson in section.lesson_set.all():
24 if lesson.level not in lessons:
25 newdict = SortedDict()
26 newdict['synthetic'] = []
27 newdict['course'] = []
28 lessons[lesson.level] = newdict
29 if lesson.type not in lessons[lesson.level]:
30 lessons[lesson.level][lesson.type] = []
31 lessons[lesson.level][lesson.type].append(lesson)
36 @register.inclusion_tag("catalogue/snippets/lesson_nav.html")
37 def lesson_nav(lesson):
38 if lesson.type == 'course':
40 siblings = root.lesson_set.filter(type='course')
43 siblings = Lesson.objects.filter(type=lesson.type)
50 @register.inclusion_tag("catalogue/snippets/lesson_link.html")
52 return {'lesson': Lesson.objects.get(slug=WLURI(uri).slug)}
55 def person_list(persons):
56 return u", ".join(Person.from_text(p).readable() for p in persons)
59 # FIXME: Move to fnpdjango
62 @register.inclusion_tag('catalogue/latest_blog_posts.html')
63 def latest_blog_posts(feed_url, posts_to_show=5):
65 feed = feedparser.parse(str(feed_url))
67 for i in range(posts_to_show):
68 pub_date = feed['entries'][i].updated_parsed
69 published = datetime.date(pub_date[0], pub_date[1], pub_date[2] )
71 'title': feed['entries'][i].title,
72 'summary': feed['entries'][i].summary,
73 'link': feed['entries'][i].link,
76 return {'posts': posts}