Skip to content

Commit

Permalink
ProgressMeterMacro: Applied an altered version of bof's patch and thu…
Browse files Browse the repository at this point in the history
…s enabled addressing the actual ticket from within a ProgressMeterMacro call contained in its description; refs #8917.

git-svn-id: https://trac-hacks.org/svn/progressmetermacro@10563 7322e99d-02ea-0310-aa39-e9a107903beb
  • Loading branch information
andrejtokarcik committed Aug 8, 2011
1 parent 47181a5 commit 8032344
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 0.11/progressmeter/macro.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import os
import re

from trac.config import ExtensionOption
from trac.core import *
Expand Down Expand Up @@ -38,6 +39,14 @@ class ProgressMeterMacro(WikiMacroBase):
which is used to collect statistics on groups of tickets
for meters generated by the ProgressMeterMacro plugin.""")

def _this_ticket(self, req):
assert req.path_info != '/newticket', "Attempt to preview a progress " \
"meter pointing to this ticket, which does not exist yet."

match = re.match(r'/ticket/([0-9]+)$', req.path_info)
if match:
return match.group(1)

def expand_macro(self, formatter, name, content):
req = formatter.req

Expand All @@ -47,6 +56,13 @@ def expand_macro(self, formatter, name, content):
kwargs['format'] = 'count' # hack the `format' arg in order to display
# all-tickets stats when no args are supplied

# special case for values equal to '#': replace with current
# ticket number, if available
for key in kwargs.keys():
if kwargs[key] == '#':
current_ticket = self._this_ticket(req)
if current_ticket: kwargs[key] = current_ticket

# Create & execute the query string
qstr = '&'.join(['%s=%s' % item
for item in kwargs.iteritems()])
Expand Down
16 changes: 16 additions & 0 deletions 0.12/progressmeter/macro.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import os
import re

from trac.config import ExtensionOption
from trac.core import *
Expand Down Expand Up @@ -38,6 +39,14 @@ class ProgressMeterMacro(WikiMacroBase):
which is used to collect statistics on groups of tickets
for meters generated by the ProgressMeterMacro plugin.""")

def _this_ticket(self, req):
assert req.path_info != '/newticket', "Attempt to preview a progress " \
"meter pointing to this ticket, which does not exist yet."

match = re.match(r'/ticket/([0-9]+)$', req.path_info)
if match:
return match.group(1)

def expand_macro(self, formatter, name, content):
req = formatter.req

Expand All @@ -48,6 +57,13 @@ def expand_macro(self, formatter, name, content):
kwargs['format'] = 'count' # hack the `format' arg in order to display
# all-tickets stats when no args are supplied

# special case for values equal to '#': replace with current
# ticket number, if available
for key in kwargs.keys():
if kwargs[key] == '#':
current_ticket = self._this_ticket(req)
if current_ticket: kwargs[key] = current_ticket

# Create & execute the query string
qstr = '&'.join(['%s=%s' % item
for item in kwargs.iteritems()])
Expand Down

0 comments on commit 8032344

Please sign in to comment.