mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
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
13 lines
533 B
Python
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)
|