bookmedia too long file name fix,
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 8 Feb 2011 12:16:52 +0000 (13:16 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 8 Feb 2011 12:16:52 +0000 (13:16 +0100)
sorl-thumbnail<10 requirement

apps/catalogue/models.py
apps/catalogue/tests/__init__.py
apps/catalogue/tests/bookmedia.py [new file with mode: 0644]
requirements.txt

index ab480d7..8411f47 100644 (file)
@@ -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
 
 
index 2366653..9c0163a 100644 (file)
@@ -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 (file)
index 0000000..a9f76e9
--- /dev/null
@@ -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)
+
index 4c075af..0139514 100644 (file)
@@ -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