Matt Wilson schrieb:
> On Aug 19, 9:34 pm, Jorge Godoy <[EMAIL PROTECTED]> wrote:
>>         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?
(...)
> Yeah, I figured that's *how* I could do it.  I'm curious about if I
> *should* do it this way.  Is there some subtle danger in this
> approach?

I do something similar which does work really well for me: I have validator 
which transforms
a given id into the appropriate model object (so I have a specific validator 
for every model
object [1]) and that does work really well.

Say the user want to view an invoice. The controller function just gets the 
invoice id but
inside the function I can just work on the invoice and don't have to care about 
looking in the
db, handling errors (not found, no db connection) etc.

So if you try to validate ids, then use the validator to transform these ids 
into model
objects. Else you gain next to nothing because the id could be deleted in the 
db by the time
your code enters your controller function.

fs

[1] I have a base validator and just subclass these. So writing a new validator 
for another
model object is just a matter of 3-4 lines if "configuration" code.

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