コード例 #1
0
ファイル: base.py プロジェクト: wonderpl/dolly-web
 def _process_image_data(self, form, model=None):
     for field in form:
         if isinstance(field, wtf.FileField):
             data = None
             cfgkey = self.model.__table__.columns.get(field.name).type.cfgkey
             aoi = form.data.get(field.name + '_aoi')
             if aoi:
                 aoi = get_box_value(aoi)
             if field.data:
                 # New image upload
                 data = field.data
             elif aoi and model and not getattr(model, field.name + '_aoi') == aoi:
                 # Same image, aoi updated - need to fetch the image data
                 data = getattr(model, field.name).original
             else:
                 # Allow form to be edited without replacing existing image
                 form._fields.pop(field.name)
             if data:
                 try:
                     if not isinstance(data, FileStorage):
                         data = get_external_resource(data)
                     field.data = resize_and_upload(data, cfgkey, aoi)
                 except IOError, e:
                     # The form has already been validated at this stage but
                     # if we return False then BaseModelView.create_view will
                     # still drop through and render the errors
                     field.errors = [getattr(e, 'message', str(e))]
                     return False
コード例 #2
0
ファイル: base.py プロジェクト: wonderpl/dolly-web
def _box_validator(form, field):
    try:
        get_box_value(field.data)
    except (SyntaxError, AssertionError):
        raise wtf.ValidationError('Must be of the form: [x1, y1, x2, y2]')