Edgewall Software

Ticket #2409: olpc_default_query.patch

File olpc_default_query.patch, 2.9 KB (added by nkantrowitz, 21 months ago)

Patch for controlling the default query directly. (against r5255)

  • trac/ticket/query.py

     
    1919from datetime import datetime, timedelta 
    2020import re 
    2121from StringIO import StringIO 
     22import string 
    2223 
    2324from genshi.builder import tag 
    2425 
     
    3839                            INavigationContributor, Chrome 
    3940from trac.wiki.api import IWikiSyntaxProvider, parse_args 
    4041from trac.wiki.macros import WikiMacroBase # TODO: should be moved in .api 
     42from trac.config import Option 
    4143 
    4244 
    4345class QuerySyntaxError(Exception): 
     
    518520 
    519521    implements(IRequestHandler, INavigationContributor, IWikiSyntaxProvider, 
    520522               IContentConverter) 
     523                
     524    default_query = Option('query', 'default_query',  
     525                           default='status=new|assigned|reopened&owner=$USER', 
     526                           doc='The default query for authenticated users.') 
     527     
     528    default_anonymous_query = Option('query', 'default_anonymous_query',  
     529                           default='status=new|assigned|reopened&cc~=$USER', 
     530                           doc='The default query for anonymous users.') 
    521531 
    522532    # IContentConverter methods 
    523533    def get_supported_conversions(self): 
     
    559569 
    560570        constraints = self._get_constraints(req) 
    561571        if not constraints and not 'order' in req.args: 
    562             # avoid displaying all tickets when the query module is invoked 
    563             # with no parameters. Instead show only open tickets, possibly 
    564             # associated with the user 
    565             constraints = {'status': ('new', 'assigned', 'reopened')} 
     572            # If no constraints are given in the URL, use the default ones. 
    566573            if req.authname and req.authname != 'anonymous': 
    567                 constraints['owner'] = (req.authname,) 
     574                qstring = self.default_query 
     575                user = req.authname 
    568576            else: 
    569577                email = req.session.get('email') 
    570578                name = req.session.get('name') 
    571                 if email or name: 
    572                     constraints['cc'] = ('~%s' % (email or name),) 
     579                qstring = self.default_anonymous_query 
     580                user = email or name or None 
     581                 
     582            if user: 
     583                qstring = string.Template(qstring).safe_substitute(USER=user) 
     584            self.log.debug('QueryModule: Using default query: %s', qstring) 
     585            constraints = Query.from_string(self.env, qstring).constraints 
     586            # Ensure no field constraints that depend on $USER are used 
     587            # if we have no username. 
     588            for field, vals in constraints.items(): 
     589                for val in vals: 
     590                    if val.endswith('$USER'): 
     591                        del constraints[field] 
    573592 
    574593        cols = req.args.get('col') 
    575594        if isinstance(cols,basestring):