V
V
Valery Semenov2012-09-21 13:22:49
Python
Valery Semenov, 2012-09-21 13:22:49

deformation. Is it possible to post-process a form within the form itself?

Is it possible to attach a function to deform that provides postprocessing of the form.

form = get_form() # функция возвращающая экзепляр deform
  appstruct = form.validate(request.POST.items()) # валидируем и получаем данные

appstruct is a set of received data. (please correct me if I'm wrong). It is desirable that the function defined earlier inside the form form be called to this data,
what is it for me ...
there are two form fields
field1 “file download from disk”
field2 “file download by url”
so that the controller does not write conditions (if field1 is loaded, then do something, if field2 is loaded, then do something) I would like to do these actions in the form postprocessing function, and take the processing result in the controller.
the preparer directive for SchemaNode will not work, because it processes one value, the element to which it is attached. You need to get all the values ​​of the form in order to operate with all the data and perhaps even add a new value to the schema.
I hope my question is clear.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gelas, 2012-09-21
@Ravall

As far as I remember, the scheme from the entire form is also ShemaNode, so the preparer must receive the entire appstruct

schema = Schema(preparer=my_preparer)
form = deform.Form(schema, buttons=('submit',))

you can also override deserialize on the form or write your own widget in which it will process both ways of uploading a file and give only one value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question