X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/1405761d13e0ba62db4b1f9a9d5fa1472142b6d0..e9673d40117e6785680fb7f1d3ce9363bcd2f078:/apps/catalogue/models/book.py?ds=sidebyside
diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py
index e6f08a91a..ea85645fa 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
@@ -274,12 +279,14 @@ class Book(models.Model):
cover_changed = old_cover != book.cover_info()
obsolete_children = set(b for b in book.children.all()
if b not in children)
+ notify_cover_changed = []
for n, child_book in enumerate(children):
+ new_child = child_book.parent != book
child_book.parent = book
child_book.parent_number = n
child_book.save()
- if cover_changed:
- child_book.parent_cover_changed()
+ if new_child or cover_changed:
+ notify_cover_changed.append(child_book)
# Disown unfaithful children and let them cope on their own.
for child in obsolete_children:
child.parent = None
@@ -287,7 +294,7 @@ class Book(models.Model):
child.save()
tasks.fix_tree_tags.delay(child)
if old_cover:
- child.parent_cover_changed()
+ notify_cover_changed.append(child)
# delete old fragments when overwriting
book.fragments.all().delete()
@@ -311,6 +318,9 @@ class Book(models.Model):
book.search_index(index_tags=search_index_tags, reuse_index=search_index_reuse)
#index_book.delay(book.id, book_info)
+ for child in notify_cover_changed:
+ child.parent_cover_changed()
+
cls.published.send(sender=book)
return book
@@ -477,19 +487,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