X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/b381ee00f38c9b3db5012d9e46155e65a8ebb9ea..0c4fa3e011fd7338ecb72a7a9d752a5e3ad1c26d:/apps/catalogue/templatetags/catalogue_tags.py diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 537e3ec56..41be051f2 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -1,4 +1,10 @@ # -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +import feedparser +import datetime + from django import template from django.template import Node, Variable from django.utils.encoding import smart_str @@ -41,17 +47,17 @@ def capfirst(text): def simple_title(tags): mapping = { 'author': u'Autor', - 'theme': u'Motyw', - 'epoch': u'Epoka', - 'genre': u'Gatunek', - 'kind': u'Rodzaj', - 'set': u'Półka', + 'theme': u'motyw', + 'epoch': u'epoka', + 'genre': u'gatunek', + 'kind': u'rodzaj', + 'set': u'półka', } title = [] for tag in tags: - title.append("%s: %s." % (mapping[tag.category], tag.name)) - return ' '.join(title) + title.append("%s: %s" % (mapping[tag.category], tag.name)) + return capfirst(', '.join(title)) @register.simple_tag @@ -132,7 +138,7 @@ def authentication_form(): def breadcrumbs(tags, search_form=True): from catalogue.forms import SearchForm context = {'tag_list': tags} - if search_form: + if search_form and len(tags) < 6: context['search_form'] = SearchForm(tags=tags) return context @@ -190,22 +196,22 @@ class CatalogueURLNode(Node): @register.inclusion_tag('catalogue/latest_blog_posts.html') -def latest_blog_posts(feed_url, posts_to_show=5): - import feedparser - import datetime - - feed = feedparser.parse(feed_url) - posts = [] - for i in range(posts_to_show): - pub_date = feed['entries'][i].updated_parsed - published = datetime.date(pub_date[0], pub_date[1], pub_date[2] ) - posts.append({ - 'title': feed['entries'][i].title, - 'summary': feed['entries'][i].summary, - 'link': feed['entries'][i].link, - 'date': published, - }) - return {'posts': posts} +def latest_blog_posts(feed_url, posts_to_show=5): + try: + feed = feedparser.parse(str(feed_url)) + posts = [] + for i in range(posts_to_show): + pub_date = feed['entries'][i].updated_parsed + published = datetime.date(pub_date[0], pub_date[1], pub_date[2] ) + posts.append({ + 'title': feed['entries'][i].title, + 'summary': feed['entries'][i].summary, + 'link': feed['entries'][i].link, + 'date': published, + }) + return {'posts': posts} + except: + return {'posts': []} @register.inclusion_tag('catalogue/tag_list.html')