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.3 2003/12/27 16:49:25 uid67467 |
---|
25 | # Should be ok now. |
---|
26 | # |
---|
27 | # Revision 1.1 2003/12/02 14:41:17 jalet |
---|
28 | # And as always, I forgot most of the new files :-) |
---|
29 | # |
---|
30 | # |
---|
31 | # |
---|
32 | |
---|
33 | from mx import DateTime |
---|
34 | |
---|
35 | from pykota.reporter import BaseReporter, PyKotaReporterError |
---|
36 | |
---|
37 | class Reporter(BaseReporter) : |
---|
38 | """HTML reporter.""" |
---|
39 | def generateReport(self) : |
---|
40 | """Produces a simple HTML report.""" |
---|
41 | self.report = [] |
---|
42 | for printer in self.printers : |
---|
43 | self.report.append('<h2 class="printername">%s</h2>' % 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 | if self.isgroup : |
---|
56 | for (group, grouppquota) in self.tool.storage.getPrinterGroupsAndQuotas(printer, self.ugnames) : |
---|
57 | oddeven += 1 |
---|
58 | if oddeven % 2 : |
---|
59 | oddevenclass = "odd" |
---|
60 | else : |
---|
61 | oddevenclass = "even" |
---|
62 | (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid) = self.getQuota(group, grouppquota) |
---|
63 | 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 " ", lifepagecounter, lifetimepaid)]))) |
---|
64 | total += pages |
---|
65 | totalmoney += money |
---|
66 | else : |
---|
67 | # default is user quota report |
---|
68 | for (user, userpquota) in self.tool.storage.getPrinterUsersAndQuotas(printer, self.ugnames) : |
---|
69 | oddeven += 1 |
---|
70 | if oddeven % 2 : |
---|
71 | oddevenclass = "odd" |
---|
72 | else : |
---|
73 | oddevenclass = "even" |
---|
74 | (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid) = self.getQuota(user, userpquota) |
---|
75 | 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 " ", lifepagecounter, lifetimepaid)]))) |
---|
76 | total += pages |
---|
77 | totalmoney += money |
---|
78 | if total or totalmoney : |
---|
79 | (tpage, tmoney) = self.getTotals(total, totalmoney) |
---|
80 | self.report.append('<tr class="totals"><td colspan="7"> </td><td align="right">%s</td><td align="right">%s</td></tr>' % (tpage, tmoney)) |
---|
81 | self.report.append('<tr class="realpagecounter"><td colspan="7"> </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 | |
---|