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

Last change on this file was 11653, checked in by Russ Tyndall, 11 years ago

Removing deprecated unused code in prep for trac1.0 re #10101

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