fetch_data and validation

20 views
Skip to first unread message

city

unread,
Nov 16, 2012, 10:56:06 PM11/16/12
to toscawidge...@googlegroups.com
Hi all,

I'm attempting to make use of your DbFormPage class to generate forms that auto-populate based on database objects.

Consider the following code:

    @expose('a_template')
    def edit(self, **kw):
        form = EditExperimentForm
        form.fetch_data(request)
        return dict(page='experiments',
                    form=form,
                    )    

    @expose()
    @validate(EditExperimentForm, error_handler=edit)
    def post_edit(self, **kw):
        ...
        transaction.commit()
        redirect('...') 

fetch_data overwites any relevant validation data, so if a user posts a form with invalid information it's immediately discarded by that method.

Granted, I can write a separate method as the error handler - but is there a simple way to determine whether or not errors have been caught by the validator? If so, I can simple put a conditional statement in there and handle whether or not I bother fetching data.

Thanks!

Paul Johnston

unread,
Nov 19, 2012, 7:50:44 AM11/19/12
to toscawidge...@googlegroups.com
Hi,

The test you can use is:

if tw2.core.request_local().get('validated_widget'):
  # error handler
else:
  form.fetch_data(request)

DbFormPage was primarily intended for using tw2 standalone; it doesn't brilliantly integrate with Pyramid. So I've no plans to tidy this up.

Paul




--
You received this message because you are subscribed to the Google Groups "ToscaWidgets-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/toscawidgets-discuss/-/ts5Uq_1vXrkJ.
To post to this group, send email to toscawidge...@googlegroups.com.
To unsubscribe from this group, send email to toscawidgets-dis...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/toscawidgets-discuss?hl=en.

Reply all
Reply to author
Forward
0 new messages