mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-05-12 15:13:10 +00:00
Create form field class; re: #163
This commit is contained in:
parent
6377f89e85
commit
56f8d1b8bc
2 changed files with 26 additions and 0 deletions
1
imagekit/forms/__init__.py
Normal file
1
imagekit/forms/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from .fields import ProcessedImageField
|
||||||
25
imagekit/forms/fields.py
Normal file
25
imagekit/forms/fields.py
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
from django.forms import ImageField
|
||||||
|
from ..specs import SpecHost
|
||||||
|
|
||||||
|
|
||||||
|
class ProcessedImageField(ImageField, SpecHost):
|
||||||
|
|
||||||
|
def __init__(self, processors=None, format=None, options=None,
|
||||||
|
autoconvert=True, spec=None, spec_id=None, *args, **kwargs):
|
||||||
|
|
||||||
|
if spec_id is None:
|
||||||
|
spec_id = '??????' # FIXME: Wher should we get this?
|
||||||
|
|
||||||
|
SpecHost.__init__(self, processors=processors, format=format,
|
||||||
|
options=options, autoconvert=autoconvert, spec=spec,
|
||||||
|
spec_id=spec_id)
|
||||||
|
super(ProcessedImageField, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def clean(self, data, initial=None):
|
||||||
|
data = super(ProcessedImageField, self).clean(data, initial)
|
||||||
|
|
||||||
|
if data:
|
||||||
|
spec = self.get_spec() # HINTS?!?!?!?!?!
|
||||||
|
data = spec.apply(data, data.name)
|
||||||
|
|
||||||
|
return data
|
||||||
Loading…
Reference in a new issue