X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ddaff853c515ef7d188523d9ef17d271901dd581..1ca6872afcca0bb6fb4c0c11fdad3b760a2362a1:/apps/catalogue/models/book.py
diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py
index 5bc1e1021..d69cf2aca 100644
--- a/apps/catalogue/models/book.py
+++ b/apps/catalogue/models/book.py
@@ -75,7 +75,7 @@ class Book(models.Model):
self.sort_key = sortify(self.title)
- ret = super(Book, self).save(force_insert, force_update)
+ ret = super(Book, self).save(force_insert, force_update, **kwargs)
if reset_short_html:
self.reset_short_html()
@@ -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
@@ -196,7 +201,7 @@ class Book(models.Model):
try:
index.index_book(self, book_info)
if index_tags:
- idx.index_tags()
+ index.index_tags()
if commit:
index.index.commit()
except Exception, e:
@@ -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
@@ -506,10 +511,11 @@ class Book(models.Model):
"""
# get relevant books and their tags
objects = cls.tagged.with_all(tags)
+ parents = objects.filter(html_file='').only('slug')
# eliminate descendants
l_tags = Tag.objects.filter(category='book',
- slug__in=[book.book_tag_slug() for book in objects.iterator()])
- descendants_keys = [book.pk for book in cls.tagged.with_any(l_tags).iterator()]
+ slug__in=[book.book_tag_slug() for book in parents.iterator()])
+ descendants_keys = [book.pk for book in cls.tagged.with_any(l_tags).only('pk').iterator()]
if descendants_keys:
objects = objects.exclude(pk__in=descendants_keys)
@@ -555,6 +561,7 @@ class Book(models.Model):
return books_by_author, orphans, books_by_parent
_audiences_pl = {
+ "SP": (1, u"szkoÅa podstawowa"),
"SP1": (1, u"szkoÅa podstawowa"),
"SP2": (1, u"szkoÅa podstawowa"),
"P": (1, u"szkoÅa podstawowa"),
@@ -564,7 +571,7 @@ class Book(models.Model):
}
def audiences_pl(self):
audiences = self.extra_info.get('audiences', [])
- audiences = sorted(set([self._audiences_pl[a] for a in audiences]))
+ audiences = sorted(set([self._audiences_pl.get(a, (99, a)) for a in audiences]))
return [a[1] for a in audiences]
def choose_fragment(self):