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?ds=inline;hp=-c Merge branch 'master' into sunburnt --- d157af1061e9f03f59ea909d7d25f4a0b41f1c0e diff --combined apps/catalogue/models/book.py index 980ad5269,ea85645fa..eab6b2de3 --- a/apps/catalogue/models/book.py +++ b/apps/catalogue/models/book.py @@@ -86,6 -86,11 +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 @@@ -189,20 -194,20 +194,20 @@@ paths = map(lambda bm: (None, bm.file.path), bm) return create_zip(paths, "%s_%s" % (self.slug, format_)) - def search_index(self, book_info=None, reuse_index=False, index_tags=True): + def search_index(self, book_info=None, index=None, index_tags=True, commit=True): import search - if reuse_index: - idx = search.ReusableIndex() - else: - idx = search.Index() - - idx.open() + if index is None: + index = search.Index() try: - idx.index_book(self, book_info) + index.index_book(self, book_info) if index_tags: - idx.index_tags() - finally: - idx.close() + index.index_tags() + if commit: + index.index.commit() + except Exception, e: + index.index.rollback() + raise e + @classmethod def from_xml_file(cls, xml_file, **kwargs): @@@ -223,7 -228,7 +228,7 @@@ @classmethod def from_text_and_meta(cls, raw_file, book_info, overwrite=False, dont_build=None, search_index=True, - search_index_tags=True, search_index_reuse=False): + search_index_tags=True): if dont_build is None: dont_build = set() dont_build = set.union(set(dont_build), set(app_settings.DONT_BUILD)) @@@ -310,7 -315,8 +315,7 @@@ getattr(book, '%s_file' % format_).build_delay() if not settings.NO_SEARCH_INDEX and search_index: - book.search_index(index_tags=search_index_tags, reuse_index=search_index_reuse) - #index_book.delay(book.id, book_info) + tasks.index_book.delay(book.id, book_info=book_info, index_tags=search_index_tags) for child in notify_cover_changed: child.parent_cover_changed() @@@ -481,19 -487,19 +486,19 @@@ 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