I have a need to augment the core query logic with extra keywords.
For example, "goal=<ticketID>" goes through logic in my Project
Management plugin to find all the tickets required to satisfy a goal
(that is, all the predecessors of the ticket ID and all their
predecessors, etc.).  I currently do that with a wrapper which
processes application-specific keywords and adds standard Query
parameters something like:

    def preQuery(self, options, this_ticket = None):
        ids = ''

        if options.get('goal'):
            ...
            nodes = options['goal'].split('|')
            ...
            # Loop getting all the predecessors of the tickets
            ...
            ids += '|'.join(nodes)

        return ids

     ....

    # Expand (or set) list of IDs to include those specified by PM
    # query meta-options (e.g., root)
    pm_id = preQuery(options, self._this_ticket())
    if pm_id != '':
        if 'id' in query_args:
            query_args['id'] += '|' + pm_id
        else:
            query_args['id'] = pm_id

    ...

    # Make the query argument
    query_args['col'] = "|".join(fields)

    # Construct the querystring.
    query_string = '&'.join(['%s=%s' %
                             (f, unicode(v)) for (f, v) in
                             query_args.iteritems()])

    # Get the Query Object.
    query = Query.from_string(self.env, query_string)

    # Get all tickets
    tickets = query.execute(self.req)

But this is kind of awkward and requires editing every piece of code
that I want to be PM-aware.  I can't, for example, do
`trac/query?goal=1234` in my address bar.  What I'd like is to define
an interface for a Query preprocessor.  Something like:

    class IQueryHelper(Interface):
        # Preprocess query arguments
        # @param options hash of query options
        # @return options after handling application-specific options
        def preProcess(self, options):
            """"Expand and remove application-specific options
                 For example {"id" : "1|3", "goal" : "7"} transformed into
                 {"id" : "1|3|4|5|6"} because 4, 5, and 6 are required for 7"""

and then have the core Query handler call any registered preprocessors.

Is there a way to do that now?  A better way to approach it?


                                    Chris

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Development" 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/trac-dev?hl=en.

Reply via email to