-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Le 12/09/2010 22:27, Diez B. Roggisch a écrit :
> Hi,
>
>> I would like to display / handle forms differently with regards to
>> users permissions. For example, I have a form to create a user; only the
>> admin can create a new user, or modify all the user's information. But
>> the user himself can modify some of his own data. I'm able to display a
>> different form for admin or user, but then how can I pass the @validate
>> decorator the form to use? Here is what I have done so far in my user
>> controller (I'm using turbogears 2.0):
>
>
> You need two things here:
>
> - some discriminating information to chose in the put-method which from
> there is to use. The best one is a hidden input field in the form which says
> which of the two forms it is.
> - instead of a form, you pass an instance of a custom object with a
> validate-method. Then, you delegate the call. Like this:
Thanks for your reply, Diez.
Got it working, this is what I have done in my controller:
...
class user_form_valid(object):
def validate(self, params, state):
f = admin_edit_user_form if in_group('ADM') else edit_user_form
return f.validate(params, state)
@validate(user_form_valid(), error_handler=edit)
@expose()
def put(self, **kw):
''' Update user in DB
...
Simple, easy and powerful indeed. TurboGears is great, just difficult to
find good information sometimes.
Thanks,
- --
Jean-Denis Girard
SysNux Systèmes Linux en Polynésie française
http://www.sysnux.pf/ Tél: +689 50 10 40 / GSM: +689 79 75 27
-----BEGIN PGP SIGNATURE-----
iEYEARECAAYFAkyOXg0ACgkQuu7Rv+oOo/i3fQCeKaMCdDe5fbJOYXQs1QFw77ix
alMAnA2f4LnYxo6BnFOoQWoFf0Iwpva0
=YQjS
-----END PGP SIGNATURE-----
--
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.