X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/66c3143bfd9b7676b3490c9fa73660fa4fff9fc3..816252d1c876647d9fee4265303308c97f9cb489:/apps/catalogue/templatetags/catalogue_tags.py diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 90cbec3b6..c1d318afd 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -1,10 +1,17 @@ # -*- 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 register = template.Library() @@ -41,17 +48,47 @@ 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)) + + +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 +98,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 +146,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("