Noufal schrieb:
> Thanks for the help everyone. I got a working solution from the tips
> here and from this page
> http://docs.turbogears.org/1.0/UnifiedControllers
>
> It's quite useful but unfortunately buried in the documentation.
OMFG. That's one piece of ugly code. And the author didn't know about
quite a few things, such as
- callables as arguments to the validate-decorator
- the error_handler decorator
- the performance penalty of on-the-fly widget creation (which might
be ignorable, but nontheless - widgets aren't supposed to be created on
the fly, usually.)
This is what should be done (ripped from working code):
add_keycodetranslation_form =
w.ListForm(fields=KeyCodeTranslationFields(),
action="save_keycode_translation",
validator=KeyCodeTranslationSchema())
@expose(template="d3mailserver.templates.admin.keycodes")
def keycodes(self, tg_errors=None):
return dict(
add_keycodetranslation_form=self.add_keycodetranslation_form)
@expose()
@validate(form=add_keycodetranslation_form)
@error_handler(keycodes)
def save_keycode_translation(self, ...):
# save the keycode
redirect("keycodes")
One display method, one store-method, that only gets called in case the
validation was successful.
Not one behemoth of nested if-elses...
Make
@validate(form=add_keycodetranslation_form)
something like
def get_form():
... # return form based on e.g. a hidden input field in
cherrypy.request
@validate(form=get_form)
And you are reade to roll with conditional validation.
Diez
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---