I'm working on a MilestoneQuery macro that allows you to use custom queries to create a milestone in any wiki field. For example: [[MilestoneQuery(owner=sid)]]
could give me a milestone view into all tickets that have ever been assigned to me. This can be used also in tickets similar to the master tickets idea (#886), assuming you flag some tickets with keywords. Attached is a diff based on trunk. I'd like to get the HTML code out of the macro.. is there a better way to do this? Also, I tried to write this as a normal macro, but had trouble because I could not load the stylesheet in a normal macro since the <head> block had already been written. Any ideas? Thanks! Sid --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Trac Development" group. To post to this group, send email to trac-dev@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/trac-dev?hl=en -~----------~----~----~----~------~----~------~--~---
Index: trac/ticket/query.py =================================================================== --- trac/ticket/query.py (revision 4144) +++ trac/ticket/query.py (working copy) @@ -33,6 +33,7 @@ INavigationContributor, Chrome from trac.wiki.api import IWikiSyntaxProvider, parse_args from trac.wiki.macros import WikiMacroBase # TODO: should be moved in .api +from trac.ticket.roadmap import calc_ticket_stats class QuerySyntaxError(Exception): @@ -750,3 +751,44 @@ return html.DL([(html.DT(ticket_anchor(ticket)), html.DD(ticket['summary'])) for ticket in tickets], class_='wiki compact') + +class MilestoneQueryMacro(WikiMacroBase): + """Macro that creates a milestone for tickets that match certain criteria. + + This macro accepts one parameter, and is required. + + The first parameter is the query itself, and uses the same syntax as for + `query:` wiki links (but '''not''' the variant syntax starting with "?"). + """ + + def render_macro(self, req, name, content): + if content == '': + raise QuerySyntaxError('You must specify a query!') + query = Query.from_string(self.env, req, content) + query.order = 'id' + tickets = query.execute(req) + if tickets: + add_stylesheet(req, 'common/css/roadmap.css') + stats = calc_ticket_stats(tickets) + return """ +<div class="milestone"> + <div class="info"> + <table class="progress"> + <tr> + <td class="closed" style="width: %d%%"><a href="/testing" title="%d of %d tickets closed"></a></td> + <td class="open" style="width: %d%%"><a href="/testing" title="%d of %d tickets active"></a></td> + </tr> + </table> + <p class="percent">%d%%</p> + <p> + <dl> + <dt>Closed tickets:</dt> + <dd><a href="asdf">%d</a></dd> + <dt>Active tickets:</dt> + <dd><a href="asdf">%d</a></dd> + </dl> + </p> + </div> +</div> """ % (stats['percent_closed'], stats['closed_tickets'], stats['total_tickets'], + stats['percent_active'], stats['active_tickets'], stats['total_tickets'], + stats['percent_closed'], stats['closed_tickets'], stats['active_tickets'])