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
RevLine 
[2538]1from pkg_resources import resource_filename
[1119]2import re
3import time
4import datetime
5import dbhelper
[3784]6from usermanual import *
[1119]7from trac.core import *
8from trac.web import IRequestHandler
[4258]9from trac.perm import IPermissionRequestor
[1119]10from trac.util import Markup
11from trac.web.chrome import add_stylesheet, add_script, \
12     INavigationContributor, ITemplateProvider
13from trac.web.href import Href
[2390]14from reportmanager import CustomReportManager
[2774]15from statuses import get_statuses
[1119]16
[2774]17#get_statuses = api.get_statuses
[1119]18
19class TimingEstimationAndBillingPage(Component):
[4255]20    implements(IPermissionRequestor, INavigationContributor, IRequestHandler, ITemplateProvider)
[1119]21
22    def __init__(self):
23        pass
24
[4255]25    # IPermissionRequestor methods
26    def get_permission_actions(self): 
[4260]27        return ["TIME_VIEW", "TIME_RECORD", ("TIME_ADMIN", ["TIME_RECORD", "TIME_VIEW"])] 
[4255]28
[1119]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)
[1365]35        dtwhen = datetime.datetime.fromtimestamp(when);
[4783]36        strwhen = "%s-%s-%s %#02d:%#02d:%#02d" % \
37                (dtwhen.year, dtwhen.month, dtwhen.day, dtwhen.hour,dtwhen.minute, dtwhen.second)
[1119]38        sql = """
39        INSERT INTO bill_date (time, set_when, str_value)
[1365]40        VALUES (%s, %s, %s)
[1119]41        """
[3784]42        dbhelper.execute_non_query(self, sql, when, now, strwhen)
[2774]43
44
[3784]45
46
47
48
[1119]49    # INavigationContributor methods
50    def get_active_navigation_item(self, req):
[4782]51        val = re.search('/Billing$', req.path_info)
52        if val and val.start() == 0:
[1119]53            return "Billing"
54        else:
55            return ""
56
57    def get_navigation_items(self, req):
[2291]58        url = req.href.Billing()
[4255]59        if req.perm.has_permission("TIME_VIEW"):
[1119]60            yield 'mainnav', "Billing", \
[4258]61                Markup('<a href="%s">%s</a>' % \
62                           (url , "Time Reports"))
[1119]63
64    # IRequestHandler methods
[2298]65    def set_request_billing_dates(self, data):
[1119]66        billing_dates = []
67        billing_time_sql = """
[1369]68        SELECT DISTINCT time as value, str_value as text
[1119]69        FROM bill_date
[7840]70        ORDER BY time DESC
[1119]71        """
[3784]72        rs = dbhelper.get_result_set(self, billing_time_sql)
[3119]73        if rs:
74            for (value, text) in rs.rows:
75                billing_info = {'text':text , 'value':value}
76                billing_dates.extend([billing_info])
[1369]77        #self.log.debug("bill-dates: %s"%billing_dates)
[2298]78        data['billing_info']["billdates"] = billing_dates
[1119]79
80    def match_request(self, req):
[4782]81        val = re.search('/Billing$', req.path_info)
82        return val and val.start() == 0
[1119]83
84    def process_request(self, req):
85        messages = []
[4258]86        req.perm.require("TIME_VIEW")
[1119]87        def addMessage(s):
88            messages.extend([s]);
89
90        if req.method == 'POST':
[4260]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")
[2390]95
96        mgr = CustomReportManager(self.env, self.log)
97        data = {};
[4255]98        data["is_time_admin"] = req.perm.has_permission("TIME_ADMIN")
[3784]99        data["statuses"] = get_statuses(self)
[2774]100        data["reports"] = mgr.get_reports_by_group(CustomReportManager.TimingAndEstimationKey);
[2390]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
[2298]108        self.set_request_billing_dates(data)
109
[1119]110        add_stylesheet(req, "Billing/billingplugin.css")
[7230]111        add_script(req, "Billing/date.js")
[1119]112        add_script(req, "Billing/linkifyer.js")
[2298]113        return 'billing.html', data, None
[3784]114
115
[1119]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
[2538]125        genshi templates.
[1119]126        """
[2298]127        rtn = [resource_filename(__name__, 'templates')]
128        return rtn
[3784]129
Note: See TracBrowser for help on using the repository browser.