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

Revision 1251, 3.8 kB (checked in by jalet, 20 years ago)

Code factorization

  • 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20#
21# $Id$
22#
23# $Log$
24# Revision 1.4  2004/01/06 15:51:46  jalet
25# Code factorization
26#
27# Revision 1.3  2003/12/27 16:49:25  uid67467
28# Should be ok now.
29#
30# Revision 1.1  2003/12/02 14:41:17  jalet
31# And as always, I forgot most of the new files :-)
32#
33#
34#
35
36from mx import DateTime
37
38from pykota.reporter import BaseReporter, PyKotaReporterError
39   
40class Reporter(BaseReporter) :   
41    """HTML reporter."""
42    def generateReport(self) :
43        """Produces a simple HTML report."""
44        self.report = []
45        if self.isgroup :
46            prefix = "Group"
47        else :   
48            prefix = "User"
49        for printer in self.printers :
50            self.report.append('<h2 class="printername">%s</h2>' % self.getPrinterTitle(printer))
51            self.report.append('<h3 class="printergracedelay">%s</h3>' % self.getPrinterGraceDelay(printer))
52            (pjob, ppage) = self.getPrinterPrices(printer)
53            self.report.append('<h4 class="priceperjob">%s</h4>' % pjob)
54            self.report.append('<h4 class="priceperpage">%s</h4>' % ppage)
55            total = 0
56            totalmoney = 0.0
57            self.report.append('<table class="pykotatable" border="1">')
58            headers = self.getReportHeader().split()
59            headers.insert(1, "LimitBy")
60            self.report.append('<tr class="pykotacolsheader">%s</tr>' % "".join(["<th>%s</th>" % h for h in headers]))
61            oddeven = 0
62            for (entry, entrypquota) in getattr(self.tool.storage, "getPrinter%ssAndQuotas" % prefix)(printer, self.ugnames) :
63                oddeven += 1
64                if oddeven % 2 :
65                    oddevenclass = "odd"
66                else :   
67                    oddevenclass = "even"
68                (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid) = self.getQuota(entry, entrypquota)
69                if datelimit :
70                    if datelimit == "DENY" :
71                        oddevenclass = "deny"
72                    else :   
73                        oddevenclass = "warn"
74                self.report.append('<tr class="%s">%s</tr>' % (oddevenclass, "".join(["<td>%s</td>" % h for h in (name, reached, pagecounter, soft, hard, balance, datelimit or "&nbsp;", lifepagecounter, lifetimepaid)])))
75                total += pages
76                totalmoney += money
77               
78            if total or totalmoney :       
79                (tpage, tmoney) = self.getTotals(total, totalmoney)
80                self.report.append('<tr class="totals"><td colspan="7">&nbsp;</td><td align="right">%s</td><td align="right">%s</td></tr>' % (tpage, tmoney))
81            self.report.append('<tr class="realpagecounter"><td colspan="7">&nbsp;</td><td align="right">%s</td></tr>' % self.getPrinterRealPageCounter(printer))
82            self.report.append('</table>')
83        if self.isgroup :   
84            self.report.append('<p class="warning">%s</p>' % _("Totals may be inaccurate if some users are members of several groups."))
85        return "\n".join(self.report)   
86                       
Note: See TracBrowser for help on using the browser.