From: Marcin Koziej Date: Wed, 24 Oct 2012 11:03:15 +0000 (+0200) Subject: Merge branch 'master' into sunburnt X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/d157af1061e9f03f59ea909d7d25f4a0b41f1c0e?hp=6e5871ce487810fa5dac891e03296c6d469ffeb3 Merge branch 'master' into sunburnt --- diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py index 980ad5269..eab6b2de3 100644 --- a/apps/catalogue/models/book.py +++ b/apps/catalogue/models/book.py @@ -86,6 +86,11 @@ class Book(models.Model): def get_absolute_url(self): return ('catalogue.views.book_detail', [self.slug]) + @staticmethod + @permalink + def create_url(slug): + return ('catalogue.views.book_detail', [slug]) + @property def name(self): return self.title @@ -481,19 +486,19 @@ class Book(models.Model): def pretty_title(self, html_links=False): book = self - names = list(book.tags.filter(category='author')) - - books = [] - while book: - books.append(book) - book = book.parent - names.extend(reversed(books)) + rel_info = book.related_info() + names = [(name, Tag.create_url('author', slug)) + for name, slug in rel_info['tags']['author']] + if 'parents' in rel_info: + books = [(name, Book.create_url(slug)) + for name, slug in rel_info['parents']] + names.extend(reversed(books)) + names.append((self.title, self.get_absolute_url())) if html_links: - names = ['%s' % (tag.get_absolute_url(), tag.name) for tag in names] + names = ['%s' % (tag[1], tag[0]) for tag in names] else: - names = [tag.name for tag in names] - + names = [tag[0] for tag in names] return ', '.join(names) @classmethod diff --git a/apps/catalogue/models/listeners.py b/apps/catalogue/models/listeners.py index 9e9fcabff..93ad2d788 100644 --- a/apps/catalogue/models/listeners.py +++ b/apps/catalogue/models/listeners.py @@ -3,13 +3,17 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.conf import settings +from django.core.cache import get_cache from django.db.models.signals import post_save, pre_delete, post_delete import django.dispatch -from catalogue.models import Tag, BookMedia, Book, Fragment +from catalogue.models import Tag, BookMedia, Book, Fragment, Collection from catalogue import tasks from newtagging.models import tags_updated +permanent_cache = get_cache('permanent') + + def _tags_updated_handler(sender, affected_tags, **kwargs): # reset tag global counter # we want Tag.changed_at updated for API to know the tag was touched @@ -40,9 +44,18 @@ def _post_save_handler(sender, instance, **kwargs): """ refresh all the short_html stuff on BookMedia update """ if sender == BookMedia: instance.book.save() + permanent_cache.delete_many([ + 'catalogue.audiobook_list', 'catalogue.daisy_list']) + elif sender == Collection: + permanent_cache.delete('catalogue.collection:%s' % instance.slug) post_save.connect(_post_save_handler) +def post_publish(sender, **kwargs): + permanent_cache.delete('catalogue.book_list') +Book.published.connect(post_publish) + + if not settings.NO_SEARCH_INDEX: @django.dispatch.receiver(post_delete, sender=Book) def _remove_book_from_index_handler(sender, instance, **kwargs): diff --git a/apps/catalogue/models/tag.py b/apps/catalogue/models/tag.py index 353d567bb..3c4509dda 100644 --- a/apps/catalogue/models/tag.py +++ b/apps/catalogue/models/tag.py @@ -71,6 +71,13 @@ class Tag(TagBase): def get_absolute_url(self): return ('catalogue.views.tagged_object_list', [self.url_chunk]) + @classmethod + @permalink + def create_url(cls, category, slug): + return ('catalogue.views.tagged_object_list', [ + '/'.join((cls.categories_dict[category], slug)) + ]) + def has_description(self): return len(self.description) > 0 has_description.short_description = _('description') diff --git a/apps/catalogue/templates/catalogue/audiobook_list.html b/apps/catalogue/templates/catalogue/audiobook_list.html index 427f89934..c74f78c74 100644 --- a/apps/catalogue/templates/catalogue/audiobook_list.html +++ b/apps/catalogue/templates/catalogue/audiobook_list.html @@ -20,17 +20,3 @@ Możecie z niej korzystać bezpłatnie i bez ograniczeń. Audiobooki nagrywają znani aktorzy, wśród nich Danuta Stenka i Jan Peszek.{% endblocktrans %}

{% endblock %} - - -{% block book_list %} - {% audiobook_tree orphans books_by_parent %} - {% for author, group in books_by_author.items %} - {% if group %} - -
-

{{ author }}

- {% audiobook_tree group books_by_parent %} -
- {% endif %} - {% endfor %} -{% endblock %} diff --git a/apps/catalogue/templates/catalogue/book_list.html b/apps/catalogue/templates/catalogue/book_list.html index a32f60f01..ddeb3ce3f 100644 --- a/apps/catalogue/templates/catalogue/book_list.html +++ b/apps/catalogue/templates/catalogue/book_list.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% load catalogue_tags chunks %} +{% load catalogue_tags %} {% block bodyid %}book-a-list{% endblock %} @@ -19,29 +19,11 @@
{% trans "Table of Content" %} - {% for index, authors in books_nav.items %} - - {% endfor %} + {{ rendered_nav }}
{% block book_list %} - {% book_tree orphans books_by_parent %} - {% for author, group in books_by_author.items %} - {% if group %} - -
-

{{ author }}

- {% book_tree group books_by_parent %} -
- {% endif %} - {% endfor %} + {{ rendered_book_list }} {% endblock %}
diff --git a/apps/catalogue/templates/catalogue/menu.html b/apps/catalogue/templates/catalogue/menu.html index 1a90b5c4a..72bf5e6fe 100644 --- a/apps/catalogue/templates/catalogue/menu.html +++ b/apps/catalogue/templates/catalogue/menu.html @@ -1,32 +1,16 @@ -{% load i18n %} -{% load tag_list from catalogue_tags %} +{% load i18n static %}