Hardy wrote:
> Hi,
> i want to write a form that adds a user. When pressing submit,i'm
> running into an error, but i don't know where it is...
>
> @expose(template="web2.templates.adduser")
> # @identity.require(identity.in_group("admin")
> def adduser(name, passwd, group):
> print name
> print passwd
> print group
> b=User(user_name=name, password=passwd, group=group)
> raise redirect("/userlist")
>
> @expose(template="web2.templates.adduser")
> # @identity.require(identity.in_group("admin")
> def doit(self):
> return dict()
> --------------------------------------------------------------------------------------------
> <form Name="Add User" Method="post" Action="/adduser">
> <p>Name: <input name="name"></input></p>
> <p>Password: <input name="passwd"></input></p>
> <p>Group: <input name="group"></input></p>
> <p><input type="submit" value="submit"></input></p>
> </form>
> ---------------------------------------------------------------------------------------------
> Page handler: <bound method Root.adduser of <web2.controllers.Root
> object at 0x88ff22c>>
> Traceback (most recent call last):
> File "/usr/lib/python2.5/site-packages/CherryPy-2.2.1-py2.5.egg/
> cherrypy/_cphttptools.py", line 105, in _run
> self.main()
> File "/usr/lib/python2.5/site-packages/CherryPy-2.2.1-py2.5.egg/
> cherrypy/_cphttptools.py", line 254, in main
> body = page_handler(*virtual_path, **self.params)
> TypeError: adduser() got multiple values for keyword argument 'name'
> >
>
Here is how I typically handle this scenario
@expose(template="web2.templates.adduser")
# @identity.require(identity.in_group("admin")
def adduser(self, *args, **kw):
print kw['name']
print kw['passwd']
print kw['group']
b=User(user_name=kw['name'], password=kw['passwd'], group=kw['group]')
raise redirect("/userlist")
But, I would also put a validator on all of the fields in my form so
that they get converted properly before using in the method. This also
requires the following error_handler and validate decorators.
Ex:
@tg.error_handler(user) <- method to process in event of validation error
@tg.validate(form=userForm) <- Form definition with validator attributes
specified
Hope this helps.
-Jim
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---