Changeset 3413 for pykota/trunk/cgi-bin/pykotme.cgi
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/cgi-bin/pykotme.cgi
r3411 r3413 11 11 # the Free Software Foundation, either version 3 of the License, or 12 12 # (at your option) any later version. 13 # 13 # 14 14 # This program is distributed in the hope that it will be useful, 15 15 # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 17 # GNU General Public License for more details. 18 # 18 # 19 19 # You should have received a copy of the GNU General Public License 20 20 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 38 38 39 39 from pkpgpdls import analyzer, pdlparser 40 40 41 41 42 42 header = """Content-type: text/html;charset=%s … … 69 69 </tr> 70 70 </table>""" 71 71 72 72 footer = """ 73 73 <table> … … 77 77 </td> 78 78 </tr> 79 </table> 79 </table> 80 80 </form> 81 81 </p> … … 84 84 <font size="-2"> 85 85 <a href="http://www.pykota.com/">%s</a> 86 © %s %s 86 © %s %s 87 87 <br /> 88 88 <pre> … … 92 92 </p> 93 93 </body> 94 </html>""" 94 </html>""" 95 95 96 96 class PyKotMeGUI(PyKotaTool) : … … 106 106 _("Quote")) ] 107 107 content.append(self.body) 108 content.append(footer % (_("Quote"), 109 version.__doc__, 110 version.__years__, 111 version.__author__, 108 content.append(footer % (_("Quote"), 109 version.__doc__, 110 version.__years__, 111 version.__author__, 112 112 saxutils.escape(version.__gplblurb__))) 113 113 for c in content : 114 114 sys.stdout.write(c.encode(self.charset, "replace")) 115 115 sys.stdout.flush() 116 116 117 117 def error(self, message) : 118 118 """Adds an error message to the GUI's body.""" 119 119 if message : 120 120 self.body = '<p><font color="red">%s</font></p>\n%s' % (message, self.body) 121 122 def htmlListPrinters(self, selected=[], mask="*") : 121 122 def htmlListPrinters(self, selected=[], mask="*") : 123 123 """Displays the printers multiple selection list.""" 124 124 printers = self.storage.getMatchingPrinters(mask) … … 132 132 message += '</select></td></tr></table>' 133 133 return message 134 134 135 135 def guiAction(self) : 136 136 """Main function""" … … 143 143 printersfield = [ printersfield ] 144 144 printers = [self.storage.getPrinter(p.value) for p in printersfield] 145 else : 145 else : 146 146 printers = self.storage.getMatchingPrinters("*") 147 if self.form.has_key("inputfile") : 147 if self.form.has_key("inputfile") : 148 148 inputfile = self.form["inputfile"].value 149 150 if os.environ.get("REMOTE_USER") is not None : 151 self.body += self.htmlListPrinters(printers or []) 149 150 if os.environ.get("REMOTE_USER") is not None : 151 self.body += self.htmlListPrinters(printers or []) 152 152 self.body += "<br />" 153 153 self.body += _("Filename") + " : " … … 158 158 parser = analyzer.PDLAnalyzer(cStringIO.StringIO(inputfile)) 159 159 jobsize = parser.getJobSize() 160 except pdlparser.PDLParserError, msg : 160 except pdlparser.PDLParserError, msg : 161 161 self.body += '<p><font color="red">%s</font></p>' % msg 162 162 jobsize = 0 # unknown file format ? 163 else : 163 else : 164 164 self.body += "<p>%s</p>" % (_("Job size : %i pages") % jobsize) 165 165 166 166 remuser = os.environ.get("REMOTE_USER") 167 167 # special hack to accomodate mod_auth_ldap Apache module 168 168 try : 169 169 remuser = remuser.split("=")[1].split(",")[0] 170 except : 170 except : 171 171 pass 172 if not remuser : 172 if not remuser : 173 173 self.body += "<p>%s</p>" % _("The exact cost of a print job can only be determined for a particular user. Please retry while logged-in.") 174 else : 175 try : 174 else : 175 try : 176 176 user = self.storage.getUser(remuser) 177 177 if user.Exists : 178 178 if user.LimitBy == "noprint" : 179 179 self.body += "<p>%s</p>" % _("Your account settings forbid you to print at this time.") 180 else : 180 else : 181 181 for printer in printers : 182 182 upquota = self.storage.getUserPQuota(user, printer) … … 184 184 if printer.MaxJobSize and (jobsize > printer.MaxJobSize) : 185 185 msg = _("You are not allowed to print so many pages on printer %s at this time.") % printer.Name 186 else : 186 else : 187 187 cost = upquota.computeJobPrice(jobsize) 188 188 msg = _("Cost on printer %s : %.2f") % (printer.Name, cost) 189 189 if printer.PassThrough : 190 190 msg = "%s (%s)" % (msg, _("won't be charged, printer is in passthrough mode")) 191 elif user.LimitBy == "nochange" : 191 elif user.LimitBy == "nochange" : 192 192 msg = "%s (%s)" % (msg, _("won't be charged, your account is immutable")) 193 193 self.body += "<p>%s</p>" % msg 194 194 except : 195 195 self.body += '<p><font color="red">%s</font></p>' % self.crashed("CGI Error").replace("\n", "<br />") 196 196 197 197 if __name__ == "__main__" : 198 198 utils.reinitcgilocale() … … 204 204 try : 205 205 admin.storage.close() 206 except (TypeError, NameError, AttributeError) : 206 except (TypeError, NameError, AttributeError) : 207 207 pass 208 208 209 209 sys.exit(0)