> Hmmm, this is normal because the same controller method showing the
> form is also validating it (with the decorator), therefore when
> called with no request params required fields fail validation and the
> form thinks it's being redisplayed so it prints errors and input
> values (all blank).
> I can think of three ways to circumventing it:

I wrote and submitted to the docs.turbogears.org server the following:

http://docs.turbogears.org/1.0/UnifiedControllers

It describes in full detail (with source code) how to combine form/ 
action controllers without any of problems associated with just  
@exposing and @validating the entire thing.  The code described also  
has the added benefit of allowing validation of forms built at  
execution time.

The gist of it is:

class MyController(Controller):
     @expose(template="project.templates.genericform")
     def index(self, **kw):
         form = MyForm(fields=MyFields())

         if kw:
             @validate(form=form)
             def get_errors(self, tg_errors=None, **data):
                 return tg_errors, data

             tg_errors, data = get_errors(self, **kw)

             if not tg_errors:
                 # Perform some action with the data in **data.
                 # **kw still contains the raw data.
                 pass

                 turbogears.flash("Some success message.")
                 turbogears.redirect("/")

             else:
                 turbogears.flash("Some error message.")

         else:
             # Supply some default data, if required.
             # Optionally supplying data allows you to combine
             # create and modify actions in one.
             data = dict(...)

         return dict(title="Foo Bar", form=form, data=stock_data)

Top Floor has been using this structure extensively without  
problems.  Enjoy!

Matthew Bevan, Systems Administrator
Top Floor Computer Systems Ltd.



--~--~---------~--~----~------------~-------~--~----~
 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to