Justin Driscoll avatar Justin Driscoll committed 861930c

spec.name now respects the upload_to path and added additional error handling to Transpose:auto

Comments (0)

Files changed (3)


     def process(cls, img, fmt, obj):
         if cls.method == 'auto':
-            orientation = Image.open(obj._imgfield.file)._getexif()[0x0112]
-            ops = cls.EXIF_ORIENTATION_STEPS[orientation]
+            try:
+                orientation = Image.open(obj._imgfield.file)._getexif()[0x0112]
+                ops = cls.EXIF_ORIENTATION_STEPS[orientation]
+            except:
+                ops = []
             ops = [cls.method]
         for method in ops:


     def _exists(self):
         return self._obj._imgfield.storage.exists(self.name)
-    def _basename(self):
-        filename, extension =  \
-            os.path.splitext(os.path.basename(self._obj._imgfield.name))
+    @property
+    def name(self):
+        filepath, basename = os.path.split(self._obj._imgfield.name)
+        filename, extension = os.path.splitext(basename)
         for processor in self.spec.processors:
             if issubclass(processor, processors.Format):
                 extension = processor.extension
-        return self._obj._ik.cache_filename_format % \
+        cache_filename = self._obj._ik.cache_filename_format % \
             {'filename': filename,
              'specname': self.spec.name(),
              'extension': extension.lstrip('.')}
-    @property
-    def name(self):
-        return os.path.join(self._obj._ik.cache_dir, self._basename())
+        return os.path.join(self._obj._ik.cache_dir, filepath, cache_filename)
     def url(self):


         self.assertEqual(self.p.cropped.height, 100)
     def test_url(self):
-        tup = (settings.MEDIA_URL, self.p._ik.cache_dir, 'test_to_width.jpeg')
+        tup = (settings.MEDIA_URL, self.p._ik.cache_dir,
+               'images/test_to_width.jpeg')
         self.assertEqual(self.p.to_width.url, "%s%s/%s" % tup)
     def tearDown(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.