Hello.

I'm trying to understand how TurboGears validation of form works.
Specifically, I want to know what TurboGears does "behind the scenes."
I have followed the tutorial on this page:
http://trac.turbogears.org/turbogears/wiki/SimpleWidgetForm. The
relevant code is this:

class Root(RootController):
    ....
    @expose(template=".templates.add")
    def add(self, tg_errors=None):
        if tg_errors:
            flash("There was a problem with the form!")
        return dict(form=comment_form)

    @expose()
    @validate(form=comment_form)
    @error_handler(add)
    def save(self, name, email, comment, notify=False):
        comments.add(name, email, comment)
        if notify:
            flash("Comment added! You will be notified.")
        else:
            flash("Comment added!")
        raise redirect("index")

What I'm wondering is how does the decorators validate and
error_handler really work? Validate seem to magically change the
arguments to save() to python objects instead of text strings. Then
the error_handler decorator I think makes a HTTPRedirect back to add()
if validation fails. But how does it manage to display the error
messages in the form? How does the form know that it should display
the values that you wrote there previously when you are redirected
back?

I would like to implement code similar to the example above, but
without using a form widget. And preferably without using the validate
and error_handler decorators. Maybe someone can show me an example of
that?

-- 
mvh Björn

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to