[1236] | 1 | # PyKota |
---|
| 2 | # -*- coding: ISO-8859-15 -*- |
---|
| 3 | |
---|
| 4 | # PyKota - Print Quotas for CUPS and LPRng |
---|
| 5 | # |
---|
[2622] | 6 | # (c) 2003, 2004, 2005, 2006 Jerome Alet <alet@librelogiciel.com> |
---|
[1236] | 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 |
---|
[2302] | 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
[1236] | 20 | # |
---|
| 21 | # $Id$ |
---|
| 22 | # |
---|
[2054] | 23 | # |
---|
[1236] | 24 | |
---|
[1274] | 25 | import os |
---|
[1278] | 26 | import urllib |
---|
[1236] | 27 | from mx import DateTime |
---|
| 28 | |
---|
| 29 | from pykota.reporter import BaseReporter, PyKotaReporterError |
---|
| 30 | |
---|
| 31 | class Reporter(BaseReporter) : |
---|
| 32 | """HTML reporter.""" |
---|
| 33 | def generateReport(self) : |
---|
| 34 | """Produces a simple HTML report.""" |
---|
| 35 | self.report = [] |
---|
[1251] | 36 | if self.isgroup : |
---|
| 37 | prefix = "Group" |
---|
| 38 | else : |
---|
| 39 | prefix = "User" |
---|
[1236] | 40 | for printer in self.printers : |
---|
[1278] | 41 | phistoryurl = { "printername" : printer.Name, "history" : 1 } |
---|
| 42 | self.report.append('<a href="%s?%s"><h2 class="printername">%s</h2></a>' % (os.environ.get("SCRIPT_NAME", ""), urllib.urlencode(phistoryurl), self.getPrinterTitle(printer))) |
---|
[1239] | 43 | self.report.append('<h3 class="printergracedelay">%s</h3>' % self.getPrinterGraceDelay(printer)) |
---|
[1236] | 44 | (pjob, ppage) = self.getPrinterPrices(printer) |
---|
[1239] | 45 | self.report.append('<h4 class="priceperjob">%s</h4>' % pjob) |
---|
| 46 | self.report.append('<h4 class="priceperpage">%s</h4>' % ppage) |
---|
[1236] | 47 | total = 0 |
---|
| 48 | totalmoney = 0.0 |
---|
[1239] | 49 | self.report.append('<table class="pykotatable" border="1">') |
---|
[1236] | 50 | headers = self.getReportHeader().split() |
---|
[1239] | 51 | headers.insert(1, "LimitBy") |
---|
| 52 | self.report.append('<tr class="pykotacolsheader">%s</tr>' % "".join(["<th>%s</th>" % h for h in headers])) |
---|
| 53 | oddeven = 0 |
---|
[1251] | 54 | for (entry, entrypquota) in getattr(self.tool.storage, "getPrinter%ssAndQuotas" % prefix)(printer, self.ugnames) : |
---|
| 55 | oddeven += 1 |
---|
| 56 | if oddeven % 2 : |
---|
| 57 | oddevenclass = "odd" |
---|
| 58 | else : |
---|
| 59 | oddevenclass = "even" |
---|
[2054] | 60 | (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid, overcharge, warncount) = self.getQuota(entry, entrypquota) |
---|
[1251] | 61 | if datelimit : |
---|
| 62 | if datelimit == "DENY" : |
---|
| 63 | oddevenclass = "deny" |
---|
[1239] | 64 | else : |
---|
[1251] | 65 | oddevenclass = "warn" |
---|
[1277] | 66 | if (not self.tool.config.getDisableHistory()) and (not self.isgroup) : |
---|
[1274] | 67 | name = '<a href="%s?username=%s&printername=%s&history=1">%s</a>' % (os.environ.get("SCRIPT_NAME", ""), name, printer.Name, name) |
---|
[2054] | 68 | 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 " ", lifepagecounter, lifetimepaid, warncount)]))) |
---|
[1251] | 69 | total += pages |
---|
| 70 | totalmoney += money |
---|
| 71 | |
---|
[1236] | 72 | if total or totalmoney : |
---|
| 73 | (tpage, tmoney) = self.getTotals(total, totalmoney) |
---|
[2054] | 74 | self.report.append('<tr class="totals"><td colspan="8"> </td><td align="right">%s</td><td align="right">%s</td><td> </td></tr>' % (tpage, tmoney)) |
---|
| 75 | self.report.append('<tr class="realpagecounter"><td colspan="8"> </td><td align="right">%s</td><td> </td></tr>' % self.getPrinterRealPageCounter(printer)) |
---|
[1236] | 76 | self.report.append('</table>') |
---|
| 77 | if self.isgroup : |
---|
[1239] | 78 | self.report.append('<p class="warning">%s</p>' % _("Totals may be inaccurate if some users are members of several groups.")) |
---|
[1236] | 79 | return "\n".join(self.report) |
---|
| 80 | |
---|