1 | #! /usr/bin/python |
---|
2 | # -*- coding: ISO-8859-15 -*- |
---|
3 | |
---|
4 | # PyKota Print Quotes generator |
---|
5 | # |
---|
6 | # PyKota - Print Quotas for CUPS and LPRng |
---|
7 | # |
---|
8 | # (c) 2003, 2004, 2005 Jerome Alet <alet@librelogiciel.com> |
---|
9 | # This program is free software; you can redistribute it and/or modify |
---|
10 | # it under the terms of the GNU General Public License as published by |
---|
11 | # the Free Software Foundation; either version 2 of the License, or |
---|
12 | # (at your option) any later version. |
---|
13 | # |
---|
14 | # This program is distributed in the hope that it will be useful, |
---|
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | # GNU General Public License for more details. |
---|
18 | # |
---|
19 | # You should have received a copy of the GNU General Public License |
---|
20 | # along with this program; if not, write to the Free Software |
---|
21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | # |
---|
23 | # $Id$ |
---|
24 | # |
---|
25 | # |
---|
26 | |
---|
27 | import sys |
---|
28 | import os |
---|
29 | import cgi |
---|
30 | import urllib |
---|
31 | |
---|
32 | from pykota import version |
---|
33 | from pykota.tool import PyKotaTool, PyKotaToolError |
---|
34 | from pykota.pdlanalyzer import PDLAnalyzer, PDLAnalyzerError |
---|
35 | from pykota.cgifuncs import getLanguagePreference, getCharsetPreference |
---|
36 | |
---|
37 | header = """Content-type: text/html |
---|
38 | |
---|
39 | <?xml version="1.0" encoding="%s"?> |
---|
40 | <html> |
---|
41 | <head> |
---|
42 | <title>%s</title> |
---|
43 | <link rel="stylesheet" type="text/css" href="/pykota.css" /> |
---|
44 | </head> |
---|
45 | <body> |
---|
46 | <form action="pykotme.cgi" method="POST"> |
---|
47 | <table> |
---|
48 | <tr> |
---|
49 | <td> |
---|
50 | <p> |
---|
51 | <a href="http://www.librelogiciel.com/software/"><img src="http://www.librelogiciel.com/software/PyKota/pykota.png" alt="PyKota's Logo" /></a> |
---|
52 | <br /> |
---|
53 | <a href="http://www.librelogiciel.com/software/">PyKota v%s</a> |
---|
54 | </p> |
---|
55 | </td> |
---|
56 | <td colspan="2"> |
---|
57 | <h1>%s</h1> |
---|
58 | </td> |
---|
59 | </tr> |
---|
60 | <tr> |
---|
61 | <td colspan="3" align="center"> |
---|
62 | <input type="submit" name="report" value="%s" /> |
---|
63 | </td> |
---|
64 | </tr> |
---|
65 | </table>""" |
---|
66 | |
---|
67 | footer = """ |
---|
68 | <table> |
---|
69 | <tr> |
---|
70 | <td colspan="3" align="center"> |
---|
71 | <input type="submit" name="report" value="%s" /> |
---|
72 | </td> |
---|
73 | </tr> |
---|
74 | </table> |
---|
75 | </form> |
---|
76 | </body> |
---|
77 | </html>""" |
---|
78 | |
---|
79 | class PyKotMeGUI(PyKotaTool) : |
---|
80 | """PyKota Quote's Generator GUI""" |
---|
81 | def guiDisplay(self) : |
---|
82 | """Displays the administrative interface.""" |
---|
83 | global header, footer |
---|
84 | print header % (self.getCharset(), _("PyKota Reports"), version.__version__, _("PyKota Quotes"), _("Quote")) |
---|
85 | print self.body |
---|
86 | print footer % _("Quote") |
---|
87 | |
---|
88 | def error(self, message) : |
---|
89 | """Adds an error message to the GUI's body.""" |
---|
90 | if message : |
---|
91 | self.body = '<p><font color="red">%s</font></p>\n%s' % (message, self.body) |
---|
92 | |
---|
93 | # def htmlListPrinters(self, selected=[], mask="*") : |
---|
94 | # """Displays the printers multiple selection list.""" |
---|
95 | # printers = self.storage.getMatchingPrinters(mask) |
---|
96 | # selectednames = [p.Name for p in selected] |
---|
97 | # message = '<table><tr><td valign="top">%s :</td><td valign="top"><select name="printers" multiple="multiple">' % _("Printer") |
---|
98 | # for printer in printers : |
---|
99 | # if printer.Name in selectednames : |
---|
100 | # message += '<option value="%s" selected="selected">%s (%s)</option>' % (printer.Name, printer.Name, printer.Description) |
---|
101 | # else : |
---|
102 | # message += '<option value="%s">%s (%s)</option>' % (printer.Name, printer.Name, printer.Description) |
---|
103 | # message += '</select></td></tr></table>' |
---|
104 | # return message |
---|
105 | |
---|
106 | def guiAction(self) : |
---|
107 | """Main function""" |
---|
108 | printers = None |
---|
109 | self.body = "<p>%s</p>\n" % _("Please click on the above button") |
---|
110 | if self.form.has_key("report") : |
---|
111 | if self.form.has_key("printers") : |
---|
112 | printersfield = self.form["printers"] |
---|
113 | if type(printersfield) != type([]) : |
---|
114 | printersfield = [ printersfield ] |
---|
115 | printers = [self.storage.getPrinter(p.value) for p in printersfield] |
---|
116 | else : |
---|
117 | printers = self.storage.getMatchingPrinters("*") |
---|
118 | |
---|
119 | #self.body += self.htmlListPrinters(printers or []) |
---|
120 | #self.body += "<br />" |
---|
121 | |
---|
122 | if __name__ == "__main__" : |
---|
123 | os.environ["LC_ALL"] = getLanguagePreference() |
---|
124 | admin = PyKotMeGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference()) |
---|
125 | admin.form = cgi.FieldStorage() |
---|
126 | admin.guiAction() |
---|
127 | admin.guiDisplay() |
---|
128 | try : |
---|
129 | admin.storage.close() |
---|
130 | except (TypeError, NameError, AttributeError) : |
---|
131 | pass |
---|
132 | |
---|
133 | sys.exit(0) |
---|