X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/1f74e9a6dc7dd2303f3271ccf4c7a3eb59e3e27e..17451e915e915e884b18cbab47aff6c9902bc6ae:/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 41be051f2..5cfa5fc0c 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -11,6 +11,8 @@ 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() @@ -45,21 +47,22 @@ 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)) + title.append("%s: %s" % (_(tag.category), tag.name)) return capfirst(', '.join(title)) +@register.simple_tag +def book_title(book, html_links=False): + return book.pretty_title(html_links) + + +@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): @@ -67,46 +70,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: @@ -115,15 +118,44 @@ 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("