[1236] | 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.1 2003/12/02 14:41:17 jalet |
---|
| 25 | # And as always, I forgot most of the new files :-) |
---|
| 26 | # |
---|
| 27 | # |
---|
| 28 | # |
---|
| 29 | |
---|
| 30 | from mx import DateTime |
---|
| 31 | |
---|
| 32 | from pykota.reporter import BaseReporter, PyKotaReporterError |
---|
| 33 | |
---|
| 34 | class Reporter(BaseReporter) : |
---|
| 35 | """HTML reporter.""" |
---|
| 36 | def generateReport(self) : |
---|
| 37 | """Produces a simple HTML report.""" |
---|
| 38 | self.report = [] |
---|
| 39 | for printer in self.printers : |
---|
| 40 | self.report.append("<h1>%s</h1>" % self.getPrinterTitle(printer)) |
---|
| 41 | self.report.append("<h2>%s</h2>" % self.getPrinterGraceDelay(printer)) |
---|
| 42 | (pjob, ppage) = self.getPrinterPrices(printer) |
---|
| 43 | self.report.append("<h3>%s</h3>" % pjob) |
---|
| 44 | self.report.append("<h3>%s</h3>" % ppage) |
---|
| 45 | total = 0 |
---|
| 46 | totalmoney = 0.0 |
---|
| 47 | self.report.append('<table border="1">') |
---|
| 48 | headers = self.getReportHeader().split() |
---|
| 49 | headers.insert(1, "LimitBy") |
---|
| 50 | self.report.append('<tr bgcolor="gold">%s</tr>' % "".join(["<th>%s</th>" % h for h in headers])) |
---|
| 51 | if self.isgroup : |
---|
| 52 | for (group, grouppquota) in self.tool.storage.getPrinterGroupsAndQuotas(printer, self.ugnames) : |
---|
| 53 | (pages, money, name, reached, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid) = self.getQuota(group, grouppquota) |
---|
| 54 | self.report.append("<tr>%s</tr>" % "".join(["<td>%s</td>" % h for h in (name, reached, pagecounter, soft, hard, balance, datelimit or " ", lifepagecounter, lifetimepaid)])) |
---|
| 55 | total += pages |
---|
| 56 | totalmoney += money |
---|
| 57 | else : |
---|
| 58 | # default is user quota report |
---|
| 59 | for (user, userpquota) in self.tool.storage.getPrinterUsersAndQuotas(printer, self.ugnames) : |
---|
| 60 | (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid) = self.getQuota(user, userpquota) |
---|
| 61 | self.report.append("<tr>%s</tr>" % "".join(["<td>%s</td>" % h for h in (name, reached, pagecounter, soft, hard, balance, datelimit or " ", lifepagecounter, lifetimepaid)])) |
---|
| 62 | total += pages |
---|
| 63 | totalmoney += money |
---|
| 64 | if total or totalmoney : |
---|
| 65 | (tpage, tmoney) = self.getTotals(total, totalmoney) |
---|
| 66 | self.report.append('<tr><td colspan="7"> </td><td align="right">%s</td><td align="right">%s</td></tr>' % (tpage, tmoney)) |
---|
| 67 | self.report.append('<tr><td colspan="7"> </td><td align="right">%s</td></tr>' % self.getPrinterRealPageCounter(printer)) |
---|
| 68 | self.report.append('</table>') |
---|
| 69 | if self.isgroup : |
---|
| 70 | self.report.append("<p>%s</p>" % _("Totals may be inaccurate if some users are members of several groups.")) |
---|
| 71 | return "\n".join(self.report) |
---|
| 72 | |
---|