Ticket #7293: dynamic_variables.diff
| File dynamic_variables.diff, 4.7 KB (added by andrei2102@…, 4 years ago) |
|---|
-
trac/ticket/report.py
34 34 from trac.util.text import to_unicode, unicode_urlencode 35 35 from trac.util.translation import _ 36 36 from trac.web.api import IRequestHandler, RequestDone 37 from trac.web.chrome import add_ctxtnav, add_link, add_s tylesheet, \37 from trac.web.chrome import add_ctxtnav, add_link, add_script, add_stylesheet, \ 38 38 INavigationContributor, Chrome 39 39 from trac.wiki import IWikiSyntaxProvider, WikiParser 40 40 … … 219 219 220 220 def _render_view(self, req, db, id): 221 221 """Retrieve the report results and pre-process them for rendering.""" 222 try:223 args = self.get_var_args(req)224 except ValueError,e:225 raise TracError(_('Report failed: %(error)s', error=e))226 222 227 223 if id == -1: 228 224 # If no particular report was requested, display … … 241 237 raise ResourceNotFound( 242 238 _('Report %(num)s does not exist.', num=id), 243 239 _('Invalid Report Number')) 244 240 241 try: 242 args = self.get_var_args(req, sql) 243 except ValueError,e: 244 raise TracError(_('Report failed: %(error)s', error=e)) 245 245 # If this is a saved custom query. redirect to the query module 246 246 # 247 247 # A saved query is either an URL query (?... or query:?...), … … 498 498 del req.session[var] 499 499 except (ValueError, KeyError): 500 500 pass 501 if len(data['args']) > 0 : 502 add_script(req, 'common/js/folding.js') 501 503 return 'report_view.html', data, None 502 504 503 505 def add_alternate_links(self, req, args): … … 578 580 579 581 return cols, info 580 582 581 def get_var_args(self, req ):583 def get_var_args(self, req, sql): 582 584 report_args = {} 585 586 def repl_literal(expr): 587 var_re = re.compile("[$]([A-Z]+)") 588 parts = var_re.split(expr[1:-1]) 589 if len(parts) == 1: 590 return [] 591 return [str(param) for param in parts[1::2]] 592 583 593 for arg in req.args.keys(): 584 594 if not arg.isupper(): 585 595 continue … … 588 598 # Set some default dynamic variables 589 599 if 'USER' not in report_args: 590 600 report_args['USER'] = req.authname 591 601 602 for arg in repl_literal(sql) : 603 if not report_args.has_key(arg) : 604 report_args[arg] = '' 605 592 606 return report_args 593 607 594 608 def sql_sub_vars(self, sql, args, db=None): … … 599 613 try: 600 614 arg = args[aname] 601 615 except KeyError: 602 raise TracError(_("Dynamic variable '%(name)s' not defined.", 603 name='$%s' % aname)) 616 arg = '' 604 617 values.append(arg) 605 618 606 619 var_re = re.compile("[$]([A-Z]+)") -
trac/ticket/templates/report_view.html
11 11 12 12 <body> 13 13 <div id="content" class="report"> 14 14 <script type="text/javascript"> 15 jQuery(document).ready(function($) { 16 $("fieldset legend").enableFolding(false); 17 }); 18 </script> 15 19 <h1>$title 16 20 <span py:if="numrows and report.id != -1" class="numrows">($numrows matches)</span> 17 21 </h1> … … 19 23 <div py:if="description" id="description" xml:space="preserve"> 20 24 ${wiki_to_html(context, description)} 21 25 </div> 22 26 <form py:if="len(args) > 1" method="GET" action=""> 27 <fieldset id="filters" > 28 <legend style="cursor: pointer;"> 29 <a href="#no1">Filters</a> 30 </legend> 31 <table> 32 <py:for each="variable in args"> 33 <py:if test="variable not in ['id', 'USER']"> 34 <tr> 35 <td>${variable}: </td> 36 <td><input type="text" name="${variable}" value="${req.args[variable] or None}" /></td> 37 </tr> 38 </py:if> 39 </py:for> 40 </table> 41 </fieldset> 42 <br /> 43 <div class="buttons" align="right"> 44 <input type="submit" value="Update" name="filter"/> 45 </div> 46 <br /> 47 </form> 23 48 <div py:if="report.id != -1" class="buttons"> 24 49 <form py:if="'REPORT_MODIFY' in perm(report.resource)" action="" method="get"> 25 50 <div>
