"venkatbo" <[EMAIL PROTECTED]> writes:

> I can basically get the AutoCompleteField widget to work
> is my app. However, I need to implement a case where:
>  . in the strings (to be matched) maintained on the
>    server-side, I'd like to specify wild-card placeholders
>    like say:
>        "Hello Mr. *fill-in*, Are you there"
>        "Hello Mr. *fill-in*, How are you"
>  . The user will be given the opportunity to enter whatever
>    they wish for "*fill-in*,"
>  . When users types a space after that, they should then
>    be shown both the possible cases of:
>        "Hello Mr. *fill-in*, Are you there"
>        "Hello Mr. *fill-in*, How are you"
>    basically ignoring whatever he filled in for the wild-card,
>    and proceeding from there on to do matches...
>
> Does anyone know if it'd be feasible to modify AutoCompleteField
> such that it ignores wild-card entries like this.

Ignore?  Just change your controller for doing what you want.  One example of
controller (one of my first, I'd probably have it different today, but it
doesn't matter since it's just an example):


    @expose(allow_json=True)
    @identity.require(
        identity.Any(
        identity.in_any_group('admin'),
        identity.has_any_permission('admin', 'rh_func_edit')))
    def search_employee(self, name, **kwords):
        # Get every employee name from the view on the database
        names = model.VEmployeeData.select(
            model.VEmployeeData.q.name.startswith(name))
        # We just need their name and ID... 
        __returned_data = [[name.name, name.id] for name in names]
        # The view can return multiple results for each employee, filter it
        # here.
        filter = []
        for __ret in __returned_data:
            if __ret in filter:
                continue
            filter.append(__ret)
        return dict(names = filter)


You'd receive their type data and you can manipulate it any way you want.  It
is just a matter of using it -- or not -- in your query.  Remember that for
SQL the wildcard is '%'.  So: 'Hello Mr. %, how are you?' would return all
strings that started with 'Hello Mr. ' (includes space!) have either nothing
or anything in the middle and end with ', how are you?'.  To search for the
type name only it would be '%<name>%' (you'd better use Python's operators if
you only want things starting / ending with some string).  To replace name in
there use standard Python's rules:  '%%%s%%' % name, for example.

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

Reply via email to