X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d98bdffdc284351da05e2ee467ace50e693d1fb7..fc8859ef3e192b8e125462ff2cbda0e5dfff3d5d:/src/catalogue/models/bookmedia.py?ds=sidebyside diff --git a/src/catalogue/models/bookmedia.py b/src/catalogue/models/bookmedia.py index 0a1544fec..c1b0c5f34 100644 --- a/src/catalogue/models/bookmedia.py +++ b/src/catalogue/models/bookmedia.py @@ -4,11 +4,11 @@ from collections import OrderedDict import json from collections import namedtuple +from django.core.files.storage import storages from django.db import models from slugify import slugify import mutagen from mutagen import id3 -from fnpdjango.storage import BofhFileSystemStorage def _file_upload_to(i, _n): @@ -21,6 +21,10 @@ def _file_upload_to(i, _n): return f'book/{ext}/{name}.{ext}' +def get_storage(): + return storages['bookmedia'] + + class BookMedia(models.Model): """Represents media attached to a book.""" FileFormat = namedtuple("FileFormat", "name ext") @@ -37,7 +41,7 @@ class BookMedia(models.Model): name = models.CharField('nazwa', max_length=512) part_name = models.CharField('nazwa części', default='', blank=True, max_length=512) index = models.IntegerField('indeks', default=0) - file = models.FileField('plik', max_length=600, upload_to=_file_upload_to, storage=BofhFileSystemStorage()) + file = models.FileField('plik', max_length=600, upload_to=_file_upload_to, storage=get_storage) duration = models.FloatField(null=True, blank=True) uploaded_at = models.DateTimeField('data utworzenia', auto_now_add=True, editable=False, db_index=True) project_description = models.CharField(max_length=2048, blank=True) @@ -89,7 +93,7 @@ class BookMedia(models.Model): except BookMedia.DoesNotExist: old = None - super(BookMedia, self).save(*args, **kwargs) + #super(BookMedia, self).save(*args, **kwargs) # remove the zip package for book with modified media if old: @@ -101,7 +105,9 @@ class BookMedia(models.Model): self.extra_info = json.dumps(extra_info) self.source_sha1 = self.read_source_sha1(self.file.path, self.type) self.duration = self.read_duration() - return super(BookMedia, self).save(*args, **kwargs) + super(BookMedia, self).save(*args, **kwargs) + self.book.update_narrators() + self.book.update_has_audio() def read_duration(self): try: