Show
Ignore:
Timestamp:
10/02/04 07:48:56 (20 years ago)
Author:
jalet
Message:

Should now correctly deal with charsets both when storing into databases and when
retrieving datas. Works with both PostgreSQL and LDAP.

Location:
pykota/trunk/pykota/storages
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1754 r1761  
    2222# 
    2323# $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# 
    2428# Revision 1.77  2004/09/28 14:29:00  jalet 
    2529# dumpykota for LDAP backend is almost there. 
     
    576580            printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 
    577581            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())  
    579583            printer.Exists = 1 
    580584        return printer     
     
    677681                    lastjob.JobPrice = None 
    678682                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())  
    681685                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())  
    683687                lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 
    684688                lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 
     
    753757                printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 
    754758                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())  
    756760                printer.Exists = 1 
    757761                printers.append(printer) 
     
    965969        """Write the printer's description back into the storage.""" 
    966970        fields = { 
    967                    "description" : str(printer.Description), 
     971                   "description" : str(printer.Description).decode(self.tool.getCharset()).encode("UTF-8"),  
    968972                 } 
    969973        self.doModify(printer.ident, fields) 
     
    10641068                   "pykotaPrinterPageCounter" : str(pagecounter), 
    10651069                   "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"),  
    10681072                   "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"),  
    10701074                   "pykotaHostName" : str(clienthost),  
    10711075                   "pykotaJobSizeBytes" : str(jobsizebytes), 
     
    11661170                    job.JobPrice = None 
    11671171                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())  
    11701174                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())  
    11721176                job.JobHostName = fields.get("pykotaHostName", [""])[0] 
    11731177                job.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 
  • pykota/trunk/pykota/storages/sql.py

    r1719 r1761  
    2222# 
    2323# $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# 
    2428# Revision 1.47  2004/09/15 07:26:20  jalet 
    2529# Data dumps are now ordered by entry creation date if applicable. 
     
    187191            printer.PricePerJob = fields.get("priceperjob") or 0.0 
    188192            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())  
    190194            printer.Exists = 1 
    191195        return printer     
     
    239243            lastjob.JobPrice = fields.get("jobprice") 
    240244            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())  
    243247            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())  
    245249            lastjob.JobDate = fields.get("jobdate") 
    246250            lastjob.JobHostName = fields.get("hostname") 
     
    301305                    printer.PricePerJob = record.get("priceperjob") or 0.0 
    302306                    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())  
    304308                    printer.Exists = 1 
    305309                    printers.append(printer) 
     
    387391    def writePrinterDescription(self, printer) :     
    388392        """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))) 
    390397         
    391398    def writeUserLimitBy(self, user, limitby) :     
     
    432439        self.doModify("UPDATE jobhistory SET jobsize=%s, jobprice=%s WHERE id=%s" % (self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(lastjob.ident))) 
    433440         
    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) : 
    435442        """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") 
    436449        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
    437450            if jobsize is not None : 
     
    493506                job.JobPrice = fields.get("jobprice") 
    494507                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())  
    497510                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())  
    499512                job.JobDate = fields.get("jobdate") 
    500513                job.JobHostName = fields.get("hostname")