X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/6e32f55e3ef50d9f7d3a291c2388c5220851a9b4..c62abdd7f36455aacc7cbd04d944576013019f53:/apps/catalogue/models.py diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index 29106b184..3704b1663 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -346,7 +346,7 @@ class Book(models.Model): cover = models.FileField(_('cover'), upload_to=book_upload_path('png'), null=True, blank=True) - ebook_formats = ['pdf', 'epub', 'mobi', 'txt'] + ebook_formats = ['pdf', 'epub', 'mobi', 'fb2', 'txt'] formats = ebook_formats + ['html', 'xml'] parent = models.ForeignKey('self', blank=True, null=True, related_name='children') @@ -482,6 +482,7 @@ class Book(models.Model): def build_html(self): from django.core.files.base import ContentFile from slughifi import slughifi + from sortify import sortify from librarian import html meta_tags = list(self.tags.filter( @@ -516,7 +517,7 @@ class Book(models.Model): tag, created = Tag.objects.get_or_create(slug=slughifi(theme_name), category='theme') if created: tag.name = theme_name - tag.sort_key = theme_name.lower() + tag.sort_key = sortify(theme_name.lower()) tag.save() themes.append(tag) if not themes: @@ -546,6 +547,9 @@ class Book(models.Model): def build_mobi(self, *args, **kwargs): """(Re)builds MOBI.""" return tasks.build_mobi.delay(self.pk, *args, **kwargs) + def build_fb2(self, *args, **kwargs): + """(Re)build FB2""" + return tasks.build_fb2.delay(self.pk, *args, **kwargs) def build_txt(self, *args, **kwargs): """(Re)builds TXT.""" return tasks.build_txt.delay(self.pk, *args, **kwargs) @@ -603,7 +607,7 @@ class Book(models.Model): @classmethod def from_text_and_meta(cls, raw_file, book_info, overwrite=False, - build_epub=True, build_txt=True, build_pdf=True, build_mobi=True, + build_epub=True, build_txt=True, build_pdf=True, build_mobi=True, build_fb2=True, search_index=True, search_index_tags=True, search_index_reuse=False): # check for parts before we do anything @@ -673,6 +677,9 @@ class Book(models.Model): if not settings.NO_BUILD_MOBI and build_mobi: book.build_mobi() + if not settings.NO_BUILD_FB2 and build_fb2: + book.build_fb2() + 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)