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