X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/88eaa6c36bd8a5eb8fe1a1b3ad1f8aaddb258d5c..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 51ee86333..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() @@ -37,6 +45,44 @@ def capfirst(text): return '' + +def simple_title(tags): + title = [] + for tag in tags: + 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 def title_from_tags(tags): def split_tags(tags): @@ -44,43 +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: @@ -89,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("