class GenericFormController(controllers.Controller):
def __init__(self, form, data_handler, intro_text="",
thank_you_message="Thank you."):
super(self.__class__, self).__init__()
self.form = form
self.data_handler = data_handler
self.intro_text = intro_text
self.thank_you_message = thank_you_message
@expose()
@validate(form=self.form)
@error_handler(self.index.im_func)
def save(self, **kwargs):
self.data_handler(**kwargs)
raise redirect('thank_you')
self.save = new.instancemethod(save, self, self.__class__)
@expose(template='.templates.form')
def index(self):
form = self.form
intro_text = self.intro_text
return dict(form=form, intro_text=intro_text)
@expose(template='.templates.form_thankyou')
def thank_you(self):
thank_you_message = self.thank_you_message
return dict(thank_you_message=thank_you_message)
It can be used like this:
register = GenericFormController(my_form, model.MyTable,
intro_text='Please fill in my form.', thank_you_message='Thank you for
filling in my form.')
Hope it's of use to people.
Ed
Is the Trac still the place to post recipes like this one?
Alberto
No, the RoughDocs[1] area of the docs site is the place for recipes
like this now.
[1]: http://docs.turbogears.org/1.0/RoughDocs
Lee
--
Lee McFadden
blog: http://www.splee.co.uk
work: http://fireflisystems.com
skype: fireflisystems
I tag posts like this to prevent this from happening. Eventually I'll
move the tagged posts to the wiki, but it's always nice when somebody
else does it for me. ;]
On Dec 9, 5:34 pm, "Karl Guertin" <grayr...@gmail.com> wrote:
> On 12/9/06, Alberto <albe...@toscat.net> wrote:
>
> > This should be saved somewhere so it doesn't get diluted in the
> > flood... :)I tag posts like this to prevent this from happening. Eventually I'll
I read this list through gmail, which does support labels. I use an
expanded set of keyboard shortcuts [1], which means I don't have to
pick it from the menu and makes using labels as tags a bit simpler.
[1] http://gr.ayre.st/~grayrest/greasemonkey/gmail/gmail-macros.user.js
(press ? for key listing)
Ed