X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/dd48571cf22a0c124b382a1c26f25204aefd05f3..63c69d54bad19d7b1939b139ad79def1e7c3c194:/apps/catalogue/models.py?ds=sidebyside diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index f811461be..5b33dcc1a 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -173,13 +173,17 @@ def book_upload_path(ext=None): # how to put related book's slug here? if not ext: ext = media.type - return 'lektura/%s.%s' % (slugify(media.name), ext) + if not media.name: + name = slugify(filename.split(".")[0]) + else: + name = slugify(media.name) + return 'lektura/%s.%s' % (name, ext) return get_dynamic_path class BookMedia(models.Model): type = models.CharField(_('type'), choices=MEDIA_FORMATS, max_length="100") - name = models.CharField(_('name'), max_length="100") + name = models.CharField(_('name'), max_length="100", blank=True) file = models.FileField(_('file'), upload_to=book_upload_path(), blank=True) uploaded_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False) @@ -208,7 +212,7 @@ class Book(models.Model): epub_file = models.FileField(_('EPUB file'), upload_to=book_upload_path('epub'), blank=True) txt_file = models.FileField(_('TXT file'), upload_to=book_upload_path('txt'), blank=True) # other files - medias = models.ManyToManyField(BookMedia) + medias = models.ManyToManyField(BookMedia, blank=True) parent = models.ForeignKey('self', blank=True, null=True, related_name='children') objects = models.Manager() @@ -351,9 +355,9 @@ class Book(models.Model): if self.has_media("txt"): formats.append(u'TXT' % self.get_media('txt').url) # other files - for m in self.media.order_by('type'): + for m in self.medias.order_by('type'): formats.append(u'%s' % m.type, m.file.url) - + formats = [mark_safe(format) for format in formats] setattr(self, key, unicode(render_to_string('catalogue/book_short.html',