On Wednesday 05 September 2007 11:09:01 badfrog wrote:
> Jorge -- That was the idea -- a list containing allowable search
> fieldnames + a textbox to type something in. Controller has an
> exposed"find" method which determines the field and value to search
> for based on parameters from the request. What I'm trying to avoid is
> the necessity to do something like
>
> if searchBy == "field1":
> foo.select(field1=search)
> elif searchBy == "field2":
> foo.select(field2=search)
>
> or to have methods like
> searchByField1
> searchByField2
>
> which all themselves would contain painfully similar foo.select calls.
> Doesn't seem very DRY to me. :)
This pattern can usually be replaced with dictionaries.
search_for = {
'option_for_field1':model.q.Field1,
'option_for_field2':model.q.Field1,
'option_for_field2':model.q.Field1,
}
foo.select(search_for[searchBy]=search)
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---