| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright 2008 Optaros, Inc. |
|---|
| 4 | # |
|---|
| 5 | |
|---|
| 6 | import os |
|---|
| 7 | |
|---|
| 8 | from trac.core import * |
|---|
| 9 | from trac.wiki.macros import WikiMacroBase |
|---|
| 10 | from trac.wiki.api import parse_args |
|---|
| 11 | from trac.util.html import html, Markup |
|---|
| 12 | from trac.web.chrome import Chrome, add_stylesheet |
|---|
| 13 | |
|---|
| 14 | from tracprojectstatus.web_ui import ProjectStatusModule |
|---|
| 15 | |
|---|
| 16 | class ProjectStatusOutlineMacro(WikiMacroBase): |
|---|
| 17 | """This macro returns a link to last status report. |
|---|
| 18 | |
|---|
| 19 | Examples: |
|---|
| 20 | {{{ |
|---|
| 21 | [[ProjectStatusOutline]] - Project Outline |
|---|
| 22 | }}} |
|---|
| 23 | |
|---|
| 24 | """ |
|---|
| 25 | |
|---|
| 26 | def expand_macro(self, formatter, name, content): |
|---|
| 27 | req = formatter.req |
|---|
| 28 | resource = formatter.resource.realm and formatter.resource or Resource('wiki', req.path_info[6:]) |
|---|
| 29 | ps_module = ProjectStatusModule(self.env) |
|---|
| 30 | |
|---|
| 31 | data={} |
|---|
| 32 | data.update(ps_module._get_project_status(req, resource)) |
|---|
| 33 | data[ps_module.summary.name] = Markup(data.get(ps_module.summary.name)) |
|---|
| 34 | data['date']=resource.id.replace(ps_module.status_wikiPath,'')[:8] |
|---|
| 35 | |
|---|
| 36 | add_stylesheet(req, 'tracprojectstatus/css/project_status.css') |
|---|
| 37 | return Chrome(self.env).render_template(req, 'macros_psoutline.html', {'ps':data}) |
|---|
| 38 | |
|---|
| 39 | class ProjectStatusMacro(WikiMacroBase): |
|---|
| 40 | """This macro returns a link to last status report. |
|---|
| 41 | |
|---|
| 42 | Examples: |
|---|
| 43 | {{{ |
|---|
| 44 | [[ProjectStatus]] - Returns the link to the last status report |
|---|
| 45 | [[ProjectStatus(Last Status Report)]] - Returns the link to the last status report with `label` |
|---|
| 46 | [[ProjectStatus(label=Last Status Report)]] - Returns the link to the last status report with `label` |
|---|
| 47 | [[ProjectStatus(date=20080208, label=Last Status Report)]] - Returns the link to status report from `date` with `label` |
|---|
| 48 | }}} |
|---|
| 49 | |
|---|
| 50 | """ |
|---|
| 51 | |
|---|
| 52 | def expand_macro(self, formatter, name, content): |
|---|
| 53 | |
|---|
| 54 | args, kargs = parse_args(content) |
|---|
| 55 | date = kargs.get('date') |
|---|
| 56 | label = kargs.get('label', len(args)>0 and args[0] or None) |
|---|
| 57 | |
|---|
| 58 | # @todo: Please fix this very inefficient last report lookup. |
|---|
| 59 | project_statuses = ProjectStatusModule(self.env)._get_project_statuses(formatter.req, limit=1, filters={'ps_state':'Active'}).get('Active',[]) |
|---|
| 60 | |
|---|
| 61 | for project_status in project_statuses: |
|---|
| 62 | if label is None: |
|---|
| 63 | if len(project_status['date'])>=8: |
|---|
| 64 | label = 'Project Status '+'-'.join(project_status['date'][s:f] for s,f in ((0,4), (4,6), (6,8))) |
|---|
| 65 | |
|---|
| 66 | add_stylesheet(formatter.req, 'tracprojectstatus/css/project_status.css') |
|---|
| 67 | return html.span(html.a(label, href=project_status['href']), |
|---|
| 68 | class_="status_%s"%(project_status['ps_ryg_status'].upper())) |
|---|
| 69 | |
|---|
| 70 | return html.span(html.a("No status report created.", href=formatter.req.href.status('index'))) |
|---|