X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/a0f904af83bea5306b09fd66d8dfa254761f5a07..f3ee4c1bfbf4e3856268fa79c63465f591f3499e:/src/catalogue/models/book.py?ds=inline diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index b2d960b67..9e0ec50ff 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -91,6 +91,7 @@ class Book(models.Model): tagged = managers.ModelTaggedItemManager(Tag) tags = managers.TagDescriptor(Tag) tag_relations = GenericRelation(Tag.intermediary_table_model) + translators = models.ManyToManyField(Tag) html_built = django.dispatch.Signal() published = django.dispatch.Signal() @@ -154,12 +155,6 @@ class Book(models.Model): def genre_unicode(self): return self.tag_unicode('genre') - def translators(self): - translators = self.get_extra_info_json().get('translators') or [] - return [ - '\xa0'.join(reversed(translator.split(', ', 1))) for translator in translators - ] - def translator(self): translators = self.get_extra_info_json().get('translators') if not translators: @@ -331,6 +326,9 @@ class Book(models.Model): total += app_settings.GET_MP3_LENGTH(media.file.path) return int(total) + def get_time(self): + return round(self.xml_file.size / 1000 * 40) + def has_media(self, type_): if type_ in Book.formats: return bool(getattr(self, "%s_file" % type_)) @@ -655,14 +653,17 @@ class Book(models.Model): meta_tags = Tag.tags_from_info(book_info) - for tag in meta_tags: + for tag, relationship in meta_tags: if not tag.for_books: tag.for_books = True tag.save() - book.tags = set(meta_tags + book_shelves) + just_tags = [t for (t, rel) in meta_tags if not rel] + book.tags = set(just_tags + book_shelves) book.save() # update sort_key_author + book.translators.set([t for (t, rel) in meta_tags if rel == 'translator']) + cover_changed = old_cover != book.cover_info() obsolete_children = set(b for b in book.children.all() if b not in children)