source: timingandestimationplugin/branches/trac0.10/timingandestimationplugin/webui.py

Last change on this file was 4783, checked in by Russ Tyndall, 15 years ago

closes #1593 made billdates render in a manner close to ISO 8601 (without TZ)

File size: 4.0 KB
Line 
1import re
2import time
3import datetime
4import dbhelper
5from usermanual import *
6from trac.log import logger_factory
7from trac.core import *
8from trac.web import IRequestHandler
9from trac.util import Markup
10from trac.web.chrome import add_stylesheet, add_script, \
11     INavigationContributor, ITemplateProvider
12from trac.web.href import Href
13from reportmanager import CustomReportManager
14
15
16
17class TimingEstimationAndBillingPage(Component):
18    implements(INavigationContributor, IRequestHandler, ITemplateProvider)
19
20    def __init__(self):
21        pass
22
23    def set_bill_date(self, username="Timing and Estimation Plugin",  when=0):
24        now = time.time()
25        if not when:
26            when = now
27        when = int(when)
28        now = int(now)
29        dtwhen = datetime.datetime.fromtimestamp(when);
30        strwhen = "%s-%s-%s %#02d:%#02d:%#02d" % \
31                (dtwhen.year, dtwhen.month, dtwhen.day, dtwhen.hour,dtwhen.minute, dtwhen.second)
32        sql = """
33        INSERT INTO bill_date (time, set_when, str_value)
34        VALUES (%s, %s, %s)
35        """
36        dbhelper.execute_non_query(self, sql, when, now, strwhen)
37
38
39
40    # INavigationContributor methods
41    def get_active_navigation_item(self, req):
42        val = re.search('/Billing$', req.path_info)
43        if val and val.start() == 0:
44            return "Billing"
45        else:
46            return ""
47
48    def get_navigation_items(self, req):
49        url = req.href.Billing()
50        if req.perm.has_permission("REPORT_VIEW"):
51            yield 'mainnav', "Billing", \
52                  Markup('<a href="%s">%s</a>' % \
53                         (url , "Management"))
54
55    # IRequestHandler methods
56    def set_request_billing_dates(self, req):
57        billing_dates = []
58        billing_time_sql = """
59        SELECT DISTINCT time as value, str_value as text
60        FROM bill_date
61        """
62        rs = dbhelper.get_result_set(self, billing_time_sql)
63        if rs:
64            for (value, text) in rs.rows:
65                billing_info = {'text':text , 'value':value}
66                billing_dates.extend([billing_info])
67        #self.log.debug("bill-dates: %s"%billing_dates)
68        req.hdf['billing_info.billdates'] = billing_dates
69
70    def match_request(self, req):
71        val = re.search('/Billing$', req.path_info)
72        return val and val.start() == 0
73
74    def process_request(self, req):
75        messages = []
76
77        def addMessage(s):
78            messages.extend([s]);
79
80        if not re.search('/Billing', req.path_info):
81            return None
82
83
84        if req.method == 'POST':
85            if req.args.has_key('setbillingtime'):
86                self.set_bill_date(req.authname)
87                addMessage("All tickets last bill date updated")
88
89        mgr = CustomReportManager(self.env, self.log)
90        req.hdf["billing_info"] = {"messages":         messages,
91                                   "href":             req.href.Billing(),
92                                   "report_base_href": req.href.report(),
93                                   "reports":          mgr.get_reports_by_group("Timing and Estimation Plugin"),
94                                   "usermanual_href":  req.href.wiki(user_manual_wiki_title),
95                                   "usermanual_title": user_manual_title
96                                   }
97        self.set_request_billing_dates(req)
98        add_stylesheet(req, "Billing/billingplugin.css")
99        add_script(req, "Billing/linkifyer.js")
100        return 'billing.cs', 'text/html'
101
102
103    # ITemplateProvider
104    def get_htdocs_dirs(self):
105        """Return the absolute path of a directory containing additional
106        static resources (such as images, style sheets, etc).
107        """
108        from pkg_resources import resource_filename
109        return [('Billing', resource_filename(__name__, 'htdocs'))]
110
111    def get_templates_dirs(self):
112        """Return the absolute path of the directory containing the provided
113        ClearSilver templates.
114        """
115        from pkg_resources import resource_filename
116        return [resource_filename(__name__, 'templates')]
117
Note: See TracBrowser for help on using the repository browser.