Changeset 1761
- Timestamp:
- 10/02/04 07:48:56 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/cgi-bin/printquota.cgi
r1693 r1761 24 24 # 25 25 # $Log$ 26 # Revision 1.37 2004/10/02 05:48:56 jalet 27 # Should now correctly deal with charsets both when storing into databases and when 28 # retrieving datas. Works with both PostgreSQL and LDAP. 29 # 26 30 # Revision 1.36 2004/09/02 10:34:09 jalet 27 31 # Fixed problem with mod_auth_ldap Apache module … … 195 199 langs = [l.strip().split(';')[0] for l in languages.split(",")] 196 200 return "%s_%s" % (langs[0], langs[0].upper()) 201 202 def getCharsetPreference() : 203 """Returns the preferred charset.""" 204 charsets = os.environ.get("HTTP_ACCEPT_CHARSET", "no charset defined") 205 charsets = [l.strip().split(';')[0] for l in charsets.split(",")] 206 return charsets[0] 197 207 198 208 class PyKotaReportGUI(PyKotaTool) : … … 351 361 if __name__ == "__main__" : 352 362 os.environ["LC_ALL"] = getLanguagePreference() 353 admin = PyKotaReportGUI(lang=os.environ["LC_ALL"] )363 admin = PyKotaReportGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference()) 354 364 admin.form = cgi.FieldStorage() 355 365 admin.guiAction() -
pykota/trunk/NEWS
r1758 r1761 22 22 PyKota NEWS : 23 23 24 - 1.20alpha19 : 25 26 - The description, filename, title, and options fields 27 are now stored as UTF-8 strings in both LDAP and PostgreSQL. 28 Proper charset is used during extraction from the database. 29 24 30 - 1.20alpha18 : 25 31 -
pykota/trunk/pykota/storages/ldapstorage.py
r1754 r1761 22 22 # 23 23 # $Log$ 24 # Revision 1.78 2004/10/02 05:48:56 jalet 25 # Should now correctly deal with charsets both when storing into databases and when 26 # retrieving datas. Works with both PostgreSQL and LDAP. 27 # 24 28 # Revision 1.77 2004/09/28 14:29:00 jalet 25 29 # dumpykota for LDAP backend is almost there. … … 576 580 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 577 581 printer.uniqueMember = fields.get("uniqueMember", []) 578 printer.Description = fields.get("description", [""])[0] 582 printer.Description = fields.get("description", [""])[0].decode("UTF-8").encode(self.tool.getCharset()) 579 583 printer.Exists = 1 580 584 return printer … … 677 681 lastjob.JobPrice = None 678 682 lastjob.JobAction = fields.get("pykotaAction", [""])[0] 679 lastjob.JobFileName = fields.get("pykotaFileName", [""])[0] 680 lastjob.JobTitle = fields.get("pykotaTitle", [""])[0] 683 lastjob.JobFileName = fields.get("pykotaFileName", [""])[0].decode("UTF-8").encode(self.tool.getCharset()) 684 lastjob.JobTitle = fields.get("pykotaTitle", [""])[0].decode("UTF-8").encode(self.tool.getCharset()) 681 685 lastjob.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 682 lastjob.JobOptions = fields.get("pykotaOptions", [""])[0] 686 lastjob.JobOptions = fields.get("pykotaOptions", [""])[0].decode("UTF-8").encode(self.tool.getCharset()) 683 687 lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 684 688 lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] … … 753 757 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 754 758 printer.uniqueMember = fields.get("uniqueMember", []) 755 printer.Description = fields.get("description", [""])[0] 759 printer.Description = fields.get("description", [""])[0].decode("UTF-8").encode(self.tool.getCharset()) 756 760 printer.Exists = 1 757 761 printers.append(printer) … … 965 969 """Write the printer's description back into the storage.""" 966 970 fields = { 967 "description" : str(printer.Description) ,971 "description" : str(printer.Description).decode(self.tool.getCharset()).encode("UTF-8"), 968 972 } 969 973 self.doModify(printer.ident, fields) … … 1064 1068 "pykotaPrinterPageCounter" : str(pagecounter), 1065 1069 "pykotaAction" : action, 1066 "pykotaFileName" : ((filename is None) and "None") or filename.decode( os.environ.get("CHARSET", "ISO-8859-15")).encode("UTF-8"),1067 "pykotaTitle" : ((title is None) and "None") or title.decode( os.environ.get("CHARSET", "ISO-8859-15")).encode("UTF-8"),1070 "pykotaFileName" : ((filename is None) and "None") or filename.decode(self.tool.getCharset()).encode("UTF-8"), 1071 "pykotaTitle" : ((title is None) and "None") or title.decode(self.tool.getCharset()).encode("UTF-8"), 1068 1072 "pykotaCopies" : str(copies), 1069 "pykotaOptions" : ((options is None) and "None") or options.decode( os.environ.get("CHARSET", "ISO-8859-15")).encode("UTF-8"),1073 "pykotaOptions" : ((options is None) and "None") or options.decode(self.tool.getCharset()).encode("UTF-8"), 1070 1074 "pykotaHostName" : str(clienthost), 1071 1075 "pykotaJobSizeBytes" : str(jobsizebytes), … … 1166 1170 job.JobPrice = None 1167 1171 job.JobAction = fields.get("pykotaAction", [""])[0] 1168 job.JobFileName = fields.get("pykotaFileName", [""])[0] 1169 job.JobTitle = fields.get("pykotaTitle", [""])[0] 1172 job.JobFileName = fields.get("pykotaFileName", [""])[0].decode("UTF-8").encode(self.tool.getCharset()) 1173 job.JobTitle = fields.get("pykotaTitle", [""])[0].decode("UTF-8").encode(self.tool.getCharset()) 1170 1174 job.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 1171 job.JobOptions = fields.get("pykotaOptions", [""])[0] 1175 job.JobOptions = fields.get("pykotaOptions", [""])[0].decode("UTF-8").encode(self.tool.getCharset()) 1172 1176 job.JobHostName = fields.get("pykotaHostName", [""])[0] 1173 1177 job.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] -
pykota/trunk/pykota/storages/sql.py
r1719 r1761 22 22 # 23 23 # $Log$ 24 # Revision 1.48 2004/10/02 05:48:56 jalet 25 # Should now correctly deal with charsets both when storing into databases and when 26 # retrieving datas. Works with both PostgreSQL and LDAP. 27 # 24 28 # Revision 1.47 2004/09/15 07:26:20 jalet 25 29 # Data dumps are now ordered by entry creation date if applicable. … … 187 191 printer.PricePerJob = fields.get("priceperjob") or 0.0 188 192 printer.PricePerPage = fields.get("priceperpage") or 0.0 189 printer.Description = fields.get("description") or ""193 printer.Description = (fields.get("description") or "").decode("UTF-8").encode(self.tool.getCharset()) 190 194 printer.Exists = 1 191 195 return printer … … 239 243 lastjob.JobPrice = fields.get("jobprice") 240 244 lastjob.JobAction = fields.get("action") 241 lastjob.JobFileName = fields.get("filename")242 lastjob.JobTitle = fields.get("title")245 lastjob.JobFileName = (fields.get("filename") or "").decode("UTF-8").encode(self.tool.getCharset()) 246 lastjob.JobTitle = (fields.get("title") or "").decode("UTF-8").encode(self.tool.getCharset()) 243 247 lastjob.JobCopies = fields.get("copies") 244 lastjob.JobOptions = fields.get("options")248 lastjob.JobOptions = (fields.get("options") or "").decode("UTF-8").encode(self.tool.getCharset()) 245 249 lastjob.JobDate = fields.get("jobdate") 246 250 lastjob.JobHostName = fields.get("hostname") … … 301 305 printer.PricePerJob = record.get("priceperjob") or 0.0 302 306 printer.PricePerPage = record.get("priceperpage") or 0.0 303 printer.Description = record.get("description") or ""307 printer.Description = (record.get("description") or "").decode("UTF-8").encode(self.tool.getCharset()) 304 308 printer.Exists = 1 305 309 printers.append(printer) … … 387 391 def writePrinterDescription(self, printer) : 388 392 """Write the printer's description back into the storage.""" 389 self.doModify("UPDATE printers SET description=%s WHERE id=%s" % (self.doQuote(printer.Description), self.doQuote(printer.ident))) 393 description = printer.Description 394 if description is not None : 395 description = printer.Description.decode(self.tool.getCharset()).encode("UTF-8"), 396 self.doModify("UPDATE printers SET description=%s WHERE id=%s" % (self.doQuote(description), self.doQuote(printer.ident))) 390 397 391 398 def writeUserLimitBy(self, user, limitby) : … … 432 439 self.doModify("UPDATE jobhistory SET jobsize=%s, jobprice=%s WHERE id=%s" % (self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(lastjob.ident))) 433 440 434 def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None) : 441 def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None) : 435 442 """Adds a job in a printer's history.""" 443 if filename is not None : 444 filename = filename.decode(self.tool.getCharset()).encode("UTF-8") 445 if title is not None : 446 title = title.decode(self.tool.getCharset()).encode("UTF-8") 447 if options is not None : 448 options = options.decode(self.tool.getCharset()).encode("UTF-8") 436 449 if (not self.disablehistory) or (not printer.LastJob.Exists) : 437 450 if jobsize is not None : … … 493 506 job.JobPrice = fields.get("jobprice") 494 507 job.JobAction = fields.get("action") 495 job.JobFileName = fields.get("filename")496 job.JobTitle = fields.get("title")508 job.JobFileName = (fields.get("filename") or "").decode("UTF-8").encode(self.tool.getCharset()) 509 job.JobTitle = (fields.get("title") or "").decode("UTF-8").encode(self.tool.getCharset()) 497 510 job.JobCopies = fields.get("copies") 498 job.JobOptions = fields.get("options")511 job.JobOptions = (fields.get("options") or "").decode("UTF-8").encode(self.tool.getCharset()) 499 512 job.JobDate = fields.get("jobdate") 500 513 job.JobHostName = fields.get("hostname") -
pykota/trunk/pykota/tool.py
r1757 r1761 22 22 # 23 23 # $Log$ 24 # Revision 1.124 2004/10/02 05:48:56 jalet 25 # Should now correctly deal with charsets both when storing into databases and when 26 # retrieving datas. Works with both PostgreSQL and LDAP. 27 # 24 28 # Revision 1.123 2004/09/29 20:20:52 jalet 25 29 # Added the winbind_separator directive to pykota.conf to allow the admin to … … 493 497 class PyKotaTool : 494 498 """Base class for all PyKota command line tools.""" 495 def __init__(self, lang=None, doc="PyKota %s (c) 2003-2004 %s" % (version.__version__, version.__author__)) :499 def __init__(self, lang=None, charset=None, doc="PyKota %s (c) 2003-2004 %s" % (version.__version__, version.__author__)) : 496 500 """Initializes the command line tool.""" 497 501 # locale stuff … … 501 505 except (locale.Error, IOError) : 502 506 gettext.NullTranslations().install() 507 508 # We can force the charset. 509 # The CHARSET environment variable is set by CUPS when printing. 510 # Else we use the current locale's one. 511 # If nothing is set, we use ISO-8859-15 widely used in western Europe. 512 self.charset = charset or os.environ.get("CHARSET") or locale.getlocale()[1] or locale.getdefaultlocale()[1] or "ISO-8859-15" 503 513 504 514 # pykota specific stuff … … 522 532 self.softwareJobSize = 0 523 533 self.softwareJobPrice = 0.0 534 self.logdebug("Charset in use : %s" % self.charset) 535 536 def getCharset(self) : 537 """Returns the charset in use.""" 538 return self.charset 524 539 525 540 def logdebug(self, message) : -
pykota/trunk/pykota/version.py
r1757 r1761 22 22 # 23 23 24 __version__ = "1.20alpha1 8_unofficial"24 __version__ = "1.20alpha19_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng.""" -
pykota/trunk/TODO
r1760 r1761 79 79 pkusers --ingroups gr1,gr2,... --outgroups gr3,gr4,... 80 80 81 - Ensures data are stored in a consistent way with Unicode82 under PostgreSQL : I can't reproduce the problem.83 84 81 - Allow the --ingroups command line option to repykota, to 85 82 report only users members of the specified groups.