Ticket #2409: olpc_default_query.patch
| File olpc_default_query.patch, 2.9 KB (added by nkantrowitz, 21 months ago) |
|---|
-
trac/ticket/query.py
19 19 from datetime import datetime, timedelta 20 20 import re 21 21 from StringIO import StringIO 22 import string 22 23 23 24 from genshi.builder import tag 24 25 … … 38 39 INavigationContributor, Chrome 39 40 from trac.wiki.api import IWikiSyntaxProvider, parse_args 40 41 from trac.wiki.macros import WikiMacroBase # TODO: should be moved in .api 42 from trac.config import Option 41 43 42 44 43 45 class QuerySyntaxError(Exception): … … 518 520 519 521 implements(IRequestHandler, INavigationContributor, IWikiSyntaxProvider, 520 522 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.') 521 531 522 532 # IContentConverter methods 523 533 def get_supported_conversions(self): … … 559 569 560 570 constraints = self._get_constraints(req) 561 571 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. 566 573 if req.authname and req.authname != 'anonymous': 567 constraints['owner'] = (req.authname,) 574 qstring = self.default_query 575 user = req.authname 568 576 else: 569 577 email = req.session.get('email') 570 578 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] 573 592 574 593 cols = req.args.get('col') 575 594 if isinstance(cols,basestring):
