django-imagekit/imagekit/models/fields/files.py
Matthew Tretter 12493b3a0d Spec host must support kwarg "hints"
The registry's `get_spec()` was already supporting kwargs as a means to
provide information about the source to the spec constructor/factory
function, but the ``SpecHost`` class wasn't capable of accepting any.
This commit rectifies that. The main goal purpose of this is to allow a
bound field (the file attached by ``ImageSpecFileDescriptor``)--and the
attached model instance--to be taken into account during the spec
instance creation.

Related: #156
2012-10-20 23:29:07 -04:00

13 lines
533 B
Python

from django.db.models.fields.files import ImageFieldFile
import os
from ...utils import suggest_extension
class ProcessedImageFieldFile(ImageFieldFile):
def save(self, name, content, save=True):
filename, ext = os.path.splitext(name)
spec = self.field.get_spec() # TODO: What "hints"?
ext = suggest_extension(name, spec.format)
new_name = '%s%s' % (filename, ext)
content = spec.apply(content, new_name)
return super(ProcessedImageFieldFile, self).save(new_name, content, save)