Em Tuesday 19 August 2008 19:43:00 Matt Wilson escreveu: > I have a controller sort of like this: > > def view_user(self, user_id): > u = model.User.get(user_id) > return dict(u=u) > > I use a validator to convert user_id into an integer already. Then I > look up the relevant user. > > I'd like some way of handling the scenario where I get a perfectly > valid integer, but not a valid user ID. > > I know I could handle this inside the controller, but I wonder if > anyone else has experimented with doing this in the validator. > > What are the merits and disadvantages of this approach?
Let me try to understand what you want.
1. You want to receive any user_id and make it an integer, even if it
is not
in the database?
2. You want to receive any user_id and make it an integer, but want to
raise
an exception if it isn't in the database?
For the first case, you can use the integer validator and it is done.
For the second case you can subclass FancyValidator and check in the database
inside your validator.
One hint: unless you are using "user_id" to operate on users other than the
one currently using the application you could try using identity's
identity.current.user, which on a method that requires an authenticated user
returns the user that is currently using the application.
Did I get you wrong?
Regards,
--
Jorge Godoy <[EMAIL PROTECTED]>
signature.asc
Description: This is a digitally signed message part.

