On Dec 7, 2006, at 1:17 PM, Ed Singleton wrote:
...

>
> For me, I have to produce lots of forms, but there's few variables
> between them (form, table, welcome message, thanbk you message, etc).
> Most of which would work fine except that the validate decorator
> complains if the form doesn't exist at the point when the function is
> decorated.  So I moved it into __init__:
>
> class FormController(controllers.Controller):
>     def __init__(self, form, table, page, intro_text="",
> thank_you="Thank you."):
>         super(FormController, self).__init__()
>         self.form = form
>         self.table = table
>         self.page = page
>         self.intro_text = intro_text
>         self.thank_you = thank_you
>
>         @expose()
>         @validate(form=self.form)
>         @error_handler(self.index)
>         def save(**kwargs):
>             table.save(**kwargs)
>             raise redirect('thank_you')
>
>         self.save = save
>
>     @expose(template='.templates.form')
>     def index(self):
>         page = self.page
>         form = self.form
>         intro_text = self.intro_text
>         return dict(page=page, form=form,
>               intro_text=intro_text)
>
>     @expose(template='.templates.form_thankyou')
>     def thank_you(self):
>         page = self.page
>         thank_you = self.thank_you
>         return dict(page=page, thank_you=
>               thank_you)
>
> It doesn't yet work, as when you save the form you get the error:
> ....
> TypeError: try_call() takes at least 2 non-keyword arguments (1 given)
>
> I'm wondering if this might be easier to do with your method of having
> a single function that does everything.  But I'm not too

When you're doing self.save = save your binding save as an unbound  
method so when it's called 'self' is not passed as first positional  
argument. You need to bind it as an instance method:

from new import instancemethod

def __init__(....):
     ...
     def save(self, **kwargs): # don't forget to specify 'self' as  
first parameter
          ....
      self.save = instancemethod(save, self, self.__class__)

Alberto

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