X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/b381ee00f38c9b3db5012d9e46155e65a8ebb9ea..84aecebd96f2bc8a27396ecf10c409a8b91e1bcc:/apps/catalogue/templatetags/catalogue_tags.py?ds=sidebyside diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 537e3ec56..6ad83a045 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -1,10 +1,18 @@ # -*- 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 from django.core.urlresolvers import reverse from django.contrib.auth.forms import UserCreationForm, AuthenticationForm from django.db.models import Q +from django.conf import settings +from django.utils.translation import ugettext as _ register = template.Library() @@ -39,19 +47,40 @@ 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', - } - title = [] for tag in tags: - title.append("%s: %s." % (mapping[tag.category], tag.name)) - return ' '.join(title) + title.append("%s: %s" % (_(tag.category), tag.name)) + return capfirst(', '.join(title)) + + +def book_stub_title(book): + return ', '.join((book.author, book.title)) + + +@register.simple_tag +def book_title(book, html_links=False): + try: + names = list(book.tags.filter(category='author')) + except AttributeError: + return book_stub_title(book) + + books = [] + while book: + books.append(book) + book = book.parent + names.extend(reversed(books)) + + if html_links: + names = ['%s' % (tag.get_absolute_url(), tag.name) for tag in names] + else: + names = [tag.name for tag in names] + + return ', '.join(names) + + +@register.simple_tag +def book_title_html(book): + return book_title(book, html_links=True) @register.simple_tag @@ -61,46 +90,46 @@ def title_from_tags(tags): for tag in 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 flection = Flection() - + self = split_tags(tags) - + title = u'' - + # Specjalny przypadek oglÄ dania wszystkich lektur na danej póÅce if len(self) == 1 and 'set' in self: return u'PóÅka %s' % self['set'] - + # Specjalny przypadek "TwórczoÅÄ w pozytywizmie", wtedy gdy tylko epoka # jest wybrana przez użytkownika if 'epoch' in self and len(self) == 1: text = u'TwórczoÅÄ w %s' % flection.get_case(unicode(self['epoch']), u'miejscownik') return capfirst(text) - + # Specjalny przypadek "Dramat w twórczoÅci Sofoklesa", wtedy gdy podane # sÄ tylko rodzaj literacki i autor if 'kind' in self and 'author' in self and len(self) == 2: - text = u'%s w twórczoÅci %s' % (unicode(self['kind']), + text = u'%s w twórczoÅci %s' % (unicode(self['kind']), flection.get_case(unicode(self['author']), u'dopeÅniacz')) return capfirst(text) - + # Przypadki ogólniejsze if 'theme' in self: title += u'Motyw %s' % unicode(self['theme']) - + if 'genre' in self: if 'theme' in self: title += u' w %s' % flection.get_case(unicode(self['genre']), u'miejscownik') else: title += unicode(self['genre']) - + if 'kind' in self or 'author' in self or 'epoch' in self: if 'genre' in self or 'theme' in self: if 'kind' in self: @@ -109,15 +138,27 @@ def title_from_tags(tags): title += u' w twórczoÅci ' else: title += u'%s ' % unicode(self.get('kind', u'twórczoÅÄ')) - + if 'author' in self: title += flection.get_case(unicode(self['author']), u'dopeÅniacz') elif 'epoch' in self: title += flection.get_case(unicode(self['epoch']), u'dopeÅniacz') - + return capfirst(title) +@register.simple_tag +def book_tree(book_list, books_by_parent): + text = "".join("