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
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
9from trac.util import Markup
10from trac.web.chrome import add_stylesheet, add_script, \
11     INavigationContributor, ITemplateProvider
12from trac.web.href import Href
[2390]13from reportmanager import CustomReportManager
[2774]14from statuses import get_statuses
[1119]15
[2774]16#get_statuses = api.get_statuses
[1119]17
18class TimingEstimationAndBillingPage(Component):
19    implements(INavigationContributor, IRequestHandler, ITemplateProvider)
20
21    def __init__(self):
[11385]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)
[1119]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)
[1365]31        dtwhen = datetime.datetime.fromtimestamp(when);
[4783]32        strwhen = "%s-%s-%s %#02d:%#02d:%#02d" % \
33                (dtwhen.year, dtwhen.month, dtwhen.day, dtwhen.hour,dtwhen.minute, dtwhen.second)
[1119]34        sql = """
35        INSERT INTO bill_date (time, set_when, str_value)
[1365]36        VALUES (%s, %s, %s)
[1119]37        """
[3784]38        dbhelper.execute_non_query(self, sql, when, now, strwhen)
[2774]39
40
[3784]41
42
43
44
[1119]45    # INavigationContributor methods
46    def get_active_navigation_item(self, req):
[4782]47        val = re.search('/Billing$', req.path_info)
48        if val and val.start() == 0:
[1119]49            return "Billing"
50        else:
51            return ""
52
53    def get_navigation_items(self, req):
[2291]54        url = req.href.Billing()
[1119]55        if req.perm.has_permission("REPORT_VIEW"):
56            yield 'mainnav', "Billing", \
57                  Markup('<a href="%s">%s</a>' % \
[1670]58                         (url , "Management"))
[1119]59
60    # IRequestHandler methods
[2298]61    def set_request_billing_dates(self, data):
[1119]62        billing_dates = []
63        billing_time_sql = """
[1369]64        SELECT DISTINCT time as value, str_value as text
[1119]65        FROM bill_date
[7840]66        ORDER BY time DESC
[1119]67        """
[3784]68        rs = dbhelper.get_result_set(self, billing_time_sql)
[3119]69        if rs:
70            for (value, text) in rs.rows:
71                billing_info = {'text':text , 'value':value}
72                billing_dates.extend([billing_info])
[1369]73        #self.log.debug("bill-dates: %s"%billing_dates)
[2298]74        data['billing_info']["billdates"] = billing_dates
[1119]75
76    def match_request(self, req):
[11385]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
[1119]81
[11385]82
[1119]83    def process_request(self, req):
[11385]84        req.perm.require(self.BILLING_PERMISSION)
[1119]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")
[2390]94
95        mgr = CustomReportManager(self.env, self.log)
96        data = {};
[3784]97        data["statuses"] = get_statuses(self)
[2774]98        data["reports"] = mgr.get_reports_by_group(CustomReportManager.TimingAndEstimationKey);
[2390]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
[2298]106        self.set_request_billing_dates(data)
107
[1119]108        add_stylesheet(req, "Billing/billingplugin.css")
[7230]109        add_script(req, "Billing/date.js")
[1119]110        add_script(req, "Billing/linkifyer.js")
[2298]111        return 'billing.html', data, None
[3784]112
113
[1119]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
[2538]123        genshi templates.
[1119]124        """
[2298]125        rtn = [resource_filename(__name__, 'templates')]
126        return rtn
[3784]127
Note: See TracBrowser for help on using the repository browser.