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