Create form field class; re: #163

This commit is contained in:
Matthew Tretter 2012-10-25 22:46:28 -04:00
parent 6377f89e85
commit 56f8d1b8bc
2 changed files with 26 additions and 0 deletions

View file

@ -0,0 +1 @@
from .fields import ProcessedImageField

25
imagekit/forms/fields.py Normal file
View 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