X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/0cae17bec6d31806615fae59a5b3945016285fbe..03819cbf7cedde10e27d18068070c14ca37ff6e8:/apps/catalogue/templatetags/catalogue_tags.py diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 8cce80de5..3c34e8cdd 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -37,6 +37,23 @@ def capfirst(text): return '' + +def simple_title(tags): + mapping = { + 'author': u'Autor', + '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 capfirst(', '.join(title)) + + @register.simple_tag def title_from_tags(tags): def split_tags(tags): @@ -45,6 +62,9 @@ def title_from_tags(tags): result[tag.category] = tag return result + # TODO: Remove this after adding flection mechanism + return simple_title(tags) + class Flection(object): def get_case(self, name, flection): return name @@ -112,7 +132,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 @@ -174,16 +194,44 @@ 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} + try: + 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} + except: + return {'posts': []} + + +@register.inclusion_tag('catalogue/tag_list.html') +def tag_list(tags, choices=None): + if choices is None: + choices = [] + if len(tags) == 1: + one_tag = tags[0] + return locals() + + +@register.inclusion_tag('catalogue/folded_tag_list.html') +def folded_tag_list(tags, choices=None): + if choices is None: + choices = [] + some_tags_hidden = False + tag_count = len(tags) + + if tag_count == 1: + one_tag = tags[0] + else: + shown_tags = [tag for tag in tags if tag.main_page] + if tag_count > len(shown_tags): + some_tags_hidden = True + return locals()