Ticket #2409: olpc_default_query2.diff
| File olpc_default_query2.diff, 2.7 KB (added by nkantrowitz, 21 months ago) |
|---|
-
trac/ticket/query.py
38 38 INavigationContributor, Chrome 39 39 from trac.wiki.api import IWikiSyntaxProvider, parse_args 40 40 from trac.wiki.macros import WikiMacroBase # TODO: should be moved in .api 41 from trac.config import Option 41 42 42 43 43 44 class QuerySyntaxError(Exception): … … 518 519 519 520 implements(IRequestHandler, INavigationContributor, IWikiSyntaxProvider, 520 521 IContentConverter) 522 523 default_query = Option('query', 'default_query', 524 default='status=new|assigned|reopened&owner=$USER', 525 doc='The default query for authenticated users.') 526 527 default_anonymous_query = Option('query', 'default_anonymous_query', 528 default='status=new|assigned|reopened&cc~=$USER', 529 doc='The default query for anonymous users.') 521 530 522 531 # IContentConverter methods 523 532 def get_supported_conversions(self): … … 559 568 560 569 constraints = self._get_constraints(req) 561 570 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')} 571 # If no constraints are given in the URL, use the default ones. 566 572 if req.authname and req.authname != 'anonymous': 567 constraints['owner'] = (req.authname,) 573 qstring = self.default_query 574 user = req.authname 568 575 else: 569 576 email = req.session.get('email') 570 577 name = req.session.get('name') 571 if email or name: 572 constraints['cc'] = ('~%s' % (email or name),) 578 qstring = self.default_anonymous_query 579 user = email or name or None 580 581 if user: 582 qstring = qstring.replace('$USER', user) 583 self.log.debug('QueryModule: Using default query: %s', qstring) 584 constraints = Query.from_string(self.env, qstring).constraints 585 # Ensure no field constraints that depend on $USER are used 586 # if we have no username. 587 for field, vals in constraints.items(): 588 for val in vals: 589 if val.endswith('$USER'): 590 del constraints[field] 573 591 574 592 cols = req.args.get('col') 575 593 if isinstance(cols,basestring):
