X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/3badd77f743883992829a1174eef7c8d5e851766..70e2bb823a0c5792580a7ad60bef9d3f33978439:/apps/catalogue/models.py diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index 1f6210d20..9f26ae5b2 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -610,8 +610,9 @@ class Book(models.Model): text = fragment.to_string() short_text = '' - if (len(MarkupString(text)) > 240): - short_text = unicode(MarkupString(text)[:160]) + markup = MarkupString(text) + if (len(markup) > 240): + short_text = unicode(markup[:160]) new_fragment = Fragment.objects.create(anchor=fragment.id, book=self, text=text, short_text=short_text) @@ -748,7 +749,8 @@ class Book(models.Model): book.build_mobi() if not settings.NO_SEARCH_INDEX and search_index: - index_book.delay(book.id, book_info) + book.search_index() + #index_book.delay(book.id, book_info) book_descendants = list(book.children.all()) descendants_tags = set() @@ -934,6 +936,16 @@ class Book(models.Model): audiences = sorted(set([self._audiences_pl[a] for a in audiences])) return [a[1] for a in audiences] + def choose_fragment(self): + tag = self.book_tag() + fragments = Fragment.tagged.with_any([tag]) + if fragments.exists(): + return fragments.order_by('?')[0] + elif self.parent: + return self.parent.choose_fragment() + else: + return None + def _has_factory(ftype): has = lambda self: bool(getattr(self, "%s_file" % ftype))