If I do not select the file and just click send, I get the following error: -
Invalid pstruct: {'upload': "b'' is not a FieldStorage instance"}
This is not the behavior that I get to deform the demo site , leaving it empty leads to a more reasonable "Required" error message.
Using my own validator as shown below does not solve the problem: -
def validate_file(node, value, **kwargs): if not value: raise colander.Invalid(node, "Please select a file") class Schema(colander.MappingSchema): excel_file = colander.SchemaNode(deform.FileData(), widget=deform.widget.FileUploadWidget(tmpstore), validator=validate_file)
I see that an error occurs, but the output of e.render()
, where e is the ValidationFailure
from form.validate
, does not match the error itself. The corresponding deform
source code is in 'widget.py', where the _FieldStorage
class checks to see if the cstruct
has a cstruct
attribute and raises its own Invalid
exception.
Here is the function that executes the verification call (a really standard bot) that returns the displayed page.
def generate_upload_form(request): form = deform.Form(upload_schema, buttons=('submit',)) if getattr(request, 'POST') and 'submit' in request.POST: try: value_dict = form.validate(request.POST.items()) except deform.ValidationFailure as e:
How can I show my own error message without deactivating the deform
codebase code?
source share