Performing autosearching from a user's point of view, you need to use
text fields (first/last name of people). From a technical point of
view, you want to work with ids (matching an id to perform database
functions is much easier and less error prone then string parsing).
To do this we modified the autocomplete widget to present two fields
instead of one:
1) The autocompelte field that everyone has grown to love
2) A new fancy hidden field to populate with non-user-friendly data
So now you can pass a tuple from the search controller
@turbogears.expose(format="json")
@identity.require(identity.in_group("user"))
def contactAutoCompelteSearch(self, obj, searchString):
contacts =
Contact.select(OR(Contact.q.firstName.contains(searchString),Contact.q.lastName.contains(searchString)))
textItems = []
for i in contacts:
textItems.append( (i.lastName + ", " + i.firstName,
i.id) )
return dict(textItems=textItems)
The autocompelte will work just as before, you can still pass in a
regular list.
@turbogears.expose(format="json")
@identity.require(identity.in_group("user"))
def contactAutoCompelteSearch(self, obj, searchString):
contacts =
Contact.select(OR(Contact.q.firstName.contains(searchString),Contact.q.lastName.contains(searchString)))
textItems = []
for i in contacts:
textItems.append( i.lastName + ", " + i.firstName)
return dict(textItems=textItems)
Tried to keep everything fully backwards compatible. However, we had to
convert it to a compound widget which does break some backward
compatibility when setting up the form (the value dictionary has to
change slightly), and when you get data back from the form. Other then
that everything should work as before. Hopefully someone smarter out
there can make it 100% backwards compatible.
Didn't think creating a new widget would be a good idea as this patch
doesn't really add that much:
http://trac.turbogears.org/turbogears/ticket/654
-Owen (and Jason)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---