X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/e0de41ae1e67c230ad1e67f34f6f4f76e53d7234..816252d1c876647d9fee4265303308c97f9cb489:/apps/catalogue/templatetags/catalogue_tags.py diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 41be051f2..c1d318afd 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -11,6 +11,7 @@ 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() @@ -53,13 +54,43 @@ def simple_title(tags): '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)) +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): @@ -67,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: @@ -115,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("