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

Revision 2054, 5.0 kB (checked in by jalet, 19 years ago)

Big database structure changes. Upgrade script is now included as well as
the new LDAP schema.
Introduction of the -o | --overcharge command line option to edpykota.
The output of repykota is more complete, but doesn't fit in 80 columns anymore.
Introduction of the new 'maxdenybanners' directive.

  • 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-2004 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.9  2005/02/13 22:02:29  jalet
25# Big database structure changes. Upgrade script is now included as well as
26# the new LDAP schema.
27# Introduction of the -o | --overcharge command line option to edpykota.
28# The output of repykota is more complete, but doesn't fit in 80 columns anymore.
29# Introduction of the new 'maxdenybanners' directive.
30#
31# Revision 1.8  2004/01/12 15:28:45  jalet
32# Now can output the user's history on several printers at the same time.
33#
34# Revision 1.7  2004/01/12 15:12:50  jalet
35# Small fix for history
36#
37# Revision 1.6  2004/01/12 14:35:01  jalet
38# Printing history added to CGI script.
39#
40# Revision 1.5  2004/01/08 14:10:33  jalet
41# Copyright year changed.
42#
43# Revision 1.4  2004/01/06 15:51:46  jalet
44# Code factorization
45#
46# Revision 1.3  2003/12/27 16:49:25  uid67467
47# Should be ok now.
48#
49# Revision 1.1  2003/12/02 14:41:17  jalet
50# And as always, I forgot most of the new files :-)
51#
52#
53#
54
55import os
56import urllib
57from mx import DateTime
58
59from pykota.reporter import BaseReporter, PyKotaReporterError
60   
61class Reporter(BaseReporter) :   
62    """HTML reporter."""
63    def generateReport(self) :
64        """Produces a simple HTML report."""
65        self.report = []
66        if self.isgroup :
67            prefix = "Group"
68        else :   
69            prefix = "User"
70        for printer in self.printers :
71            phistoryurl = { "printername" : printer.Name, "history" : 1 }
72            self.report.append('<a href="%s?%s"><h2 class="printername">%s</h2></a>' % (os.environ.get("SCRIPT_NAME", ""), urllib.urlencode(phistoryurl), self.getPrinterTitle(printer)))
73            self.report.append('<h3 class="printergracedelay">%s</h3>' % self.getPrinterGraceDelay(printer))
74            (pjob, ppage) = self.getPrinterPrices(printer)
75            self.report.append('<h4 class="priceperjob">%s</h4>' % pjob)
76            self.report.append('<h4 class="priceperpage">%s</h4>' % ppage)
77            total = 0
78            totalmoney = 0.0
79            self.report.append('<table class="pykotatable" border="1">')
80            headers = self.getReportHeader().split()
81            headers.insert(1, "LimitBy")
82            self.report.append('<tr class="pykotacolsheader">%s</tr>' % "".join(["<th>%s</th>" % h for h in headers]))
83            oddeven = 0
84            for (entry, entrypquota) in getattr(self.tool.storage, "getPrinter%ssAndQuotas" % prefix)(printer, self.ugnames) :
85                oddeven += 1
86                if oddeven % 2 :
87                    oddevenclass = "odd"
88                else :   
89                    oddevenclass = "even"
90                (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid, overcharge, warncount) = self.getQuota(entry, entrypquota)
91                if datelimit :
92                    if datelimit == "DENY" :
93                        oddevenclass = "deny"
94                    else :   
95                        oddevenclass = "warn"
96                if (not self.tool.config.getDisableHistory()) and (not self.isgroup) :
97                    name = '<a href="%s?username=%s&printername=%s&history=1">%s</a>' % (os.environ.get("SCRIPT_NAME", ""), name, printer.Name, name)
98                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 "&nbsp;", lifepagecounter, lifetimepaid, warncount)])))
99                total += pages
100                totalmoney += money
101               
102            if total or totalmoney :       
103                (tpage, tmoney) = self.getTotals(total, totalmoney)
104                self.report.append('<tr class="totals"><td colspan="8">&nbsp;</td><td align="right">%s</td><td align="right">%s</td><td>&nbsp;</td></tr>' % (tpage, tmoney))
105            self.report.append('<tr class="realpagecounter"><td colspan="8">&nbsp;</td><td align="right">%s</td><td>&nbsp;</td></tr>' % self.getPrinterRealPageCounter(printer))
106            self.report.append('</table>')
107        if self.isgroup :   
108            self.report.append('<p class="warning">%s</p>' % _("Totals may be inaccurate if some users are members of several groups."))
109        return "\n".join(self.report)   
110                       
Note: See TracBrowser for help on using the browser.