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

This commit is contained in:
Justin Driscoll 2009-07-19 15:26:53 -04:00
parent 68b8d46a2f
commit eb97ed1180
3 changed files with 13 additions and 11 deletions

View file

@ -165,8 +165,11 @@ class Transpose(ImageProcessor):
@classmethod
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 = []
else:
ops = [cls.method]
for method in ops:

View file

@ -71,20 +71,18 @@ class Accessor(object):
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)
@property
def url(self):

View file

@ -76,7 +76,8 @@ class IKTest(TestCase):
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):