> I have a problem with TG. In short: my forms are not filled in after
> there is a validation error. I know about form.display(value_dict)
> stuff, but when the errors handler is called, It is not passed the
> same arguments as an original call (I use the same function for
> handling the request and error).
Yep I hit this. Forms are easy but some things are not THAT obvious
to mere mortals like you and I. This one tripped me up and I find
myself looking for best practice rather than something which just
about works.
My solution to this when there is a verification error (found by the
controller method receiving the form data) .... you don't redirect
back to the method generating the form; you "return" it
which works (but leaves the user with an unexpected URL if they notice
it).
The example below might help ..... (it uses Kid and SqlAlchemy).
-----------------------------------------------------------------------------
@tg.expose(template='kid:myapp.manager.page.kid.add')
def add(self, *args, **kw):
return dict(form=AddForm, record=kw)
@tg.validate(AddForm)
@tg.error_handler(add)
@tg.expose( )
def add_save(self, *args, **kw):
msg_list = [ ]
#
query = session.query(Page)
record = query.get_by(Page.c.page_name==kw['page_name'])
if (record is not None):
msg_list.append('Page (%s) already exists' %
kw['page_name'])
#
if len(msg_list) > 0:
msg_list.append("SO RECORD WAS NOT ADDED!")
tg.flash("\\n".join(msg_list))
return self.add(kw) // THROWS USER BACK TO INPUT AFTER
ERROR
#
kw['page_text'] = deEntity(kw['page_text'])
#
newone = Page(**kw)
session.save(newone)
session.flush( )
raise tg.redirect("list")
-----------------------------------------------------------------------------
> So, I have two questions:
Am hoping the example gets you there, if not then shout!
Regards
A
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---