Changeset 4652
- Timestamp:
- Oct 29, 2008, 6:24:30 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
progressmetermacro/0.11/progressmeter/macro.py
r4208 r4652 10 10 from trac.web.chrome import add_stylesheet, ITemplateProvider 11 11 from trac.wiki.macros import WikiMacroBase 12 from trac.ticket.query import Query 12 from trac.ticket.query import Query, QueryModule 13 13 14 14 … … 23 23 implements(IWikiMacroProvider, ITemplateProvider) 24 24 25 # IWikiMacroProvider methods25 ## IWikiMacroProvider methods 26 26 def expand_macro(self, formatter, name, content): 27 # Stripping content -- allows using spaces within arguments --28 # and checking whether there is not argument 'status'29 content = ','.join([x.strip() for x in content.split(',') if not x.strip().startswith('status')])27 # Parsing arguments (copied from ticket/query.py from standard trac distribution) 28 # suggested by dhellmann 29 args, kwargs = parse_args(content, strict=False) 30 30 31 # Parsing arguments (copied from ticket/query.py from standard trac distribution) 32 # suggested by dhellman 33 req = formatter.req 34 query_string = '' 35 argv, kwargs = parse_args(content, strict=False) 36 if len(argv) > 0 and not 'ticket_value' in kwargs: # 0.10 compatibility hack 37 kwargs['ticket_value'] = argv[0] 31 # get statuses which will be used in the query strings 32 statuses = kwargs.pop('status', 'closed').split('|') 38 33 39 ticket_value = kwargs.pop('ticket_value', 'list').strip().lower() 40 query_string = '&'.join(['%s=%s' % item for item in kwargs.iteritems()]) 41 cnt = {} 42 qs_add = {'total': '', 'closed': '&status=closed', 'active': '&status=!closed'} 34 # Create query strings for some ticket statuses 35 _qstr = '&'.join(['%s=%s' % item 36 for item in kwargs.iteritems()]) 37 38 query_string = dict() 39 query_string['total'] = _qstr 40 41 types = {'active': '!%s', 'closed': '%s'} 42 for t in types: 43 query_string[t] = '&'.join([query_string['total'], 'status=' + 44 '|'.join([types[t] % status for status in statuses])]) 45 46 # Execute queries 47 cnt = dict() 43 48 for key in ('closed', 'total'): 44 query = Query.from_string(self.env, query_string + qs_add[key])45 tickets = query.execute( req)49 query = Query.from_string(self.env, query_string[key]) 50 tickets = query.execute(formatter.req) 46 51 cnt[key] = (tickets and len(tickets) or 0) 47 52 … … 50 55 51 56 # Getting percent of active/closed tickets 52 percents = {'closed': float(cnt['closed']) / float(cnt['total'])} 57 try: 58 percents = {'closed': float(cnt['closed']) / float(cnt['total'])} 59 except ZeroDivisionError: 60 raise Exception('No tickets found for provided constraints') 53 61 percents['active'] = 1 - percents['closed'] 54 62 63 # Start displaying 55 64 add_stylesheet(formatter.req, 'progressmeter/css/progressmeter.css') 56 57 65 main_div = tag.div(class_='milestone') 58 66 59 # Add title above progress bar60 arg v and main_div.children.append(tag.h2(argv))67 # add title above progress bar 68 args and main_div.children.append(tag.h2(args)) 61 69 62 # Add progress bar70 # add progress bar 63 71 table = tag.table(class_='progress')(tag.tr()) 72 73 # create links 74 links = dict() 75 for key in query_string: 76 # Trac QueryModule doesn't know how to handle status=x|y (what 77 # is used in the query strings) so transforming to 78 # status=x&status=y (what will be used in hyperlinks) 79 links[key] = query_string[key].replace('|', '&status=') 64 80 65 81 for key in reversed(percents.keys()): … … 68 84 table.children[0](tag.td(style='width: '+percents[key], class_=key) 69 85 (tag.a(title="%i of %i tickets %s" % (cnt[key], cnt['total'], key.title()), 70 href="%s?%s" % (formatter.href.query(), query_string + qs_add[key]))))86 href="%s?%s" % (formatter.href.query(), links[key])))) 71 87 main_div.children.append(table) 72 88 73 # Add percentage displaied to the right of the progress bar89 # add percentage displaied to the right of the progress bar 74 90 percent_para = tag.p(class_='percent')(percents['closed']) 75 91 main_div.children.append(percent_para) 76 92 77 # Add ticket count below progress bar93 # add ticket count below progress bar 78 94 ticket_count = tag.dl() 79 95 80 for key in qs_add.keys():96 for key in links.keys(): 81 97 ticket_count.children.append(tag.dt()("%s tickets:" % key.title())) 82 98 ticket_count.children.append(tag.dd()(tag.a(str(cnt[key]), 83 href="%s?%s" % (formatter.href.query(), query_string + qs_add[key]))))99 href="%s?%s" % (formatter.href.query(), links[key])))) 84 100 main_div.children.append(ticket_count) 85 101 … … 87 103 88 104 89 # ITemplateProvider methods105 ## ITemplateProvider methods 90 106 def get_htdocs_dirs(self): 91 """ Makes the 'htdocs' folder available for Trac."""107 """Makes the 'htdocs' folder available for Trac.""" 92 108 from pkg_resources import resource_filename 93 109 return [('progressmeter', resource_filename('progressmeter', 'htdocs'))]
Note: See TracChangeset
for help on using the changeset viewer.