From: Radek Czajka Date: Tue, 8 Feb 2011 12:16:52 +0000 (+0100) Subject: bookmedia too long file name fix, X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/a39b207ad55440ed2b3edcedd765a3228f8001e3?ds=sidebyside;hp=c6eaa20b4ddb98a2d085bb588224c36115334c52 bookmedia too long file name fix, sorl-thumbnail<10 requirement --- diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index ab480d7fc..8411f477e 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -156,7 +156,7 @@ class Tag(TagBase): # TODO: why is this hard-coded ? -def book_upload_path(ext=None): +def book_upload_path(ext=None, maxlen=100): def get_dynamic_path(media, filename, ext=ext): # how to put related book's slug here? if not ext: @@ -165,7 +165,7 @@ def book_upload_path(ext=None): name = slughifi(filename.split(".")[0]) else: name = slughifi(media.name) - return 'lektura/%s.%s' % (name, ext) + return 'lektura/%s.%s' % (name[:(maxlen-len('lektura/.%s' % ext))], ext) return get_dynamic_path diff --git a/apps/catalogue/tests/__init__.py b/apps/catalogue/tests/__init__.py index 2366653de..9c0163aad 100644 --- a/apps/catalogue/tests/__init__.py +++ b/apps/catalogue/tests/__init__.py @@ -1,4 +1,5 @@ from catalogue.tests.book_import import * +from catalogue.tests.bookmedia import * from catalogue.tests.search import * from catalogue.tests.tags import * from catalogue.tests.templatetags import * diff --git a/apps/catalogue/tests/bookmedia.py b/apps/catalogue/tests/bookmedia.py new file mode 100644 index 000000000..a9f76e941 --- /dev/null +++ b/apps/catalogue/tests/bookmedia.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +from django.core.files.base import ContentFile + +from catalogue.test_utils import * +from catalogue import models + +class BookMediaTests(WLTestCase): + + def test_long_name(self): + file = ContentFile('X') + bm = models.BookMedia.objects.create(type="ogg", + name="Some very very very very very very very very very very very very very very very very long file name") + bm.file.save(bm.name, file) + bm.save() + + # reload to see what was really saved + bm = models.BookMedia.objects.get(pk=bm.pk) + self.assertEqual(bm.file.size, 1) + diff --git a/requirements.txt b/requirements.txt index 4c075afe1..0139514b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,7 +13,7 @@ Feedparser>=4.1 # PIL PIL>=1.1.6 mutagen>=1.17 -sorl-thumbnail>=3.2 +sorl-thumbnail>=3.2,<10 # home-brewed & dependencies lxml>=2.2.2