-# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
#
from collections import OrderedDict
import json
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_))
@classmethod
def from_text_and_meta(cls, raw_file, book_info, overwrite=False, dont_build=None, search_index=True,
- remote_gallery_url=None, days=0, findable=True):
+ remote_gallery_url=None, days=0, findable=True, logo=None, logo_mono=None, logo_alt=None):
from catalogue import tasks
if dont_build is None:
book.common_slug = book_info.variant_of.slug
else:
book.common_slug = book.slug
- book.extra_info = json.dumps(book_info.to_dict())
+ extra = book_info.to_dict()
+ if logo:
+ extra['logo'] = logo
+ if logo_mono:
+ extra['logo_mono'] = logo_mono
+ if logo_alt:
+ extra['logo_alt'] = logo_alt
+ book.extra_info = json.dumps(extra)
book.load_abstract()
book.load_toc()
book.save()
else:
entity, entity_created = Entity.objects.get_or_create(uri=uri)
if entity_created:
- entity.populate()
- entity.save()
+ try:
+ entity.populate()
+ except:
+ pass
+ else:
+ entity.save()
ref, ref_created = entity.reference_set.get_or_create(book=self)
refs[uri] = ref
if not ref_created: