root / pykota / trunk / pykota / reporters / html.py @ 3184

Revision 3184, 4.1 kB (checked in by jerome, 17 years ago)

Added some docstrings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1# PyKota
2# -*- coding: ISO-8859-15 -*-
3
4# PyKota - Print Quotas for CUPS and LPRng
5#
6# (c) 2003, 2004, 2005, 2006, 2007 Jerome Alet <alet@librelogiciel.com>
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20#
21# $Id$
22#
23#
24
25"""This module defines a class for HTML reporting."""
26
27import os
28import urllib
29
30from pykota.reporter import BaseReporter
31   
32class Reporter(BaseReporter) :   
33    """HTML reporter."""
34    def generateReport(self) :
35        """Produces a simple HTML report."""
36        self.report = []
37        if self.isgroup :
38            prefix = "Group"
39        else :   
40            prefix = "User"
41        for printer in self.printers :
42            phistoryurl = { "printername" : printer.Name, "history" : 1 }
43            self.report.append('<a href="%s?%s"><h2 class="printername">%s</h2></a>' % (os.environ.get("SCRIPT_NAME", ""), urllib.urlencode(phistoryurl), self.getPrinterTitle(printer)))
44            self.report.append('<h3 class="printergracedelay">%s</h3>' % self.getPrinterGraceDelay(printer))
45            (pjob, ppage) = self.getPrinterPrices(printer)
46            self.report.append('<h4 class="priceperjob">%s</h4>' % pjob)
47            self.report.append('<h4 class="priceperpage">%s</h4>' % ppage)
48            total = 0
49            totalmoney = 0.0
50            self.report.append('<table class="pykotatable" border="1">')
51            headers = self.getReportHeader().split()
52            headers.insert(1, "LimitBy")
53            self.report.append('<tr class="pykotacolsheader">%s</tr>' % "".join(["<th>%s</th>" % h for h in headers]))
54            oddeven = 0
55            for (entry, entrypquota) in getattr(self.tool.storage, "getPrinter%ssAndQuotas" % prefix)(printer, self.ugnames) :
56                oddeven += 1
57                if oddeven % 2 :
58                    oddevenclass = "odd"
59                else :   
60                    oddevenclass = "even"
61                (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid, overcharge, warncount) = self.getQuota(entry, entrypquota)
62                if datelimit :
63                    if datelimit == "DENY" :
64                        oddevenclass = "deny"
65                    else :   
66                        oddevenclass = "warn"
67                if (not self.tool.config.getDisableHistory()) and (not self.isgroup) :
68                    name = '<a href="%s?username=%s&printername=%s&history=1">%s</a>' % (os.environ.get("SCRIPT_NAME", ""), name, printer.Name, name)
69                self.report.append('<tr class="%s">%s</tr>' % (oddevenclass, "".join(["<td>%s</td>" % h for h in (name, reached, overcharge, pagecounter, soft, hard, balance, datelimit or "&nbsp;", lifepagecounter, lifetimepaid, warncount)])))
70                total += pages
71                totalmoney += money
72               
73            if total or totalmoney :       
74                (tpage, tmoney) = self.getTotals(total, totalmoney)
75                self.report.append('<tr class="totals"><td colspan="8">&nbsp;</td><td align="right">%s</td><td align="right">%s</td><td>&nbsp;</td></tr>' % (tpage, tmoney))
76            self.report.append('<tr class="realpagecounter"><td colspan="8">&nbsp;</td><td align="right">%s</td><td>&nbsp;</td></tr>' % self.getPrinterRealPageCounter(printer))
77            self.report.append('</table>')
78        if self.isgroup :   
79            self.report.append('<p class="warning">%s</p>' % _("Totals may be inaccurate if some users are members of several groups."))
80        return "\n".join(self.report)   
81                       
Note: See TracBrowser for help on using the browser.