Index: /pykota/trunk/pykota/storages/sql.py
===================================================================
--- /pykota/trunk/pykota/storages/sql.py (revision 1787)
+++ /pykota/trunk/pykota/storages/sql.py (revision 1790)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.56  2004/10/07 21:14:28  jalet
+# Hopefully final fix for data encoding to and from the database
+#
 # Revision 1.55  2004/10/07 09:37:53  jalet
 # Fixes recently introduced bug wrt users groups (was it three days ago ?)
@@ -114,8 +117,5 @@
                     field = fields[j]
                     if type(field) == StringType :
-                        try :
-                            fields[j] = unicode(field, "UTF-8").encode(self.tool.getCharset()) 
-                        except UnicodeError : # takes care of old jobs in history not stored as UTF-8    
-                            pass
+                        fields[j] = self.databaseToUserCharset(field) 
                 entries[i] = tuple(fields)    
             return entries
@@ -224,5 +224,5 @@
             printer.PricePerJob = fields.get("priceperjob") or 0.0
             printer.PricePerPage = fields.get("priceperpage") or 0.0
-            printer.Description = unicode((fields.get("description") or ""), "UTF-8").encode(self.tool.getCharset()) 
+            printer.Description = self.databaseToUserCharset(fields.get("description") or "")
             printer.Exists = 1
         return printer    
@@ -276,8 +276,8 @@
             lastjob.JobPrice = fields.get("jobprice")
             lastjob.JobAction = fields.get("action")
-            lastjob.JobFileName = unicode((fields.get("filename") or ""), "UTF-8").encode(self.tool.getCharset()) 
-            lastjob.JobTitle = unicode((fields.get("title") or ""), "UTF-8").encode(self.tool.getCharset()) 
+            lastjob.JobFileName = self.databaseToUserCharset(fields.get("filename") or "") 
+            lastjob.JobTitle = self.databaseToUserCharset(fields.get("title") or "") 
             lastjob.JobCopies = fields.get("copies")
-            lastjob.JobOptions = unicode((fields.get("options") or ""), "UTF-8").encode(self.tool.getCharset()) 
+            lastjob.JobOptions = self.databaseToUserCharset(fields.get("options") or "") 
             lastjob.JobDate = fields.get("jobdate")
             lastjob.JobHostName = fields.get("hostname")
@@ -338,5 +338,5 @@
                     printer.PricePerJob = record.get("priceperjob") or 0.0
                     printer.PricePerPage = record.get("priceperpage") or 0.0
-                    printer.Description = unicode((record.get("description") or ""), "UTF-8").encode(self.tool.getCharset()) 
+                    printer.Description = self.databaseToUserCharset(record.get("description") or "") 
                     printer.Exists = 1
                     printers.append(printer)
@@ -424,7 +424,5 @@
     def writePrinterDescription(self, printer) :    
         """Write the printer's description back into the storage."""
-        description = printer.Description
-        if description is not None :
-            description = unicode(printer.Description, self.tool.getCharset()).encode("UTF-8"), 
+        description = self.userCharsetToDatabase(printer.Description)
         self.doModify("UPDATE printers SET description=%s WHERE id=%s" % (self.doQuote(description), self.doQuote(printer.ident)))
         
@@ -474,10 +472,7 @@
     def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None) :
         """Adds a job in a printer's history."""
-        if filename is not None :
-            filename = unicode(filename, self.tool.getCharset()).encode("UTF-8")
-        if title is not None :
-            title = unicode(title, self.tool.getCharset()).encode("UTF-8")
-        if options is not None :
-            options = unicode(options, self.tool.getCharset()).encode("UTF-8")
+        filename = self.userCharsetToDatabase(filename)
+        title = self.userCharsetToDatabase(title)
+        options = self.userCharsetToDatabase(options)
         if (not self.disablehistory) or (not printer.LastJob.Exists) :
             if jobsize is not None :
@@ -539,8 +534,8 @@
                 job.JobPrice = fields.get("jobprice")
                 job.JobAction = fields.get("action")
-                job.JobFileName = unicode((fields.get("filename") or ""), "UTF-8").encode(self.tool.getCharset()) 
-                job.JobTitle = unicode((fields.get("title") or ""), "UTF-8").encode(self.tool.getCharset()) 
+                job.JobFileName = self.databaseToUserCharset(fields.get("filename") or "") 
+                job.JobTitle = self.databaseToUserCharset(fields.get("title") or "") 
                 job.JobCopies = fields.get("copies")
-                job.JobOptions = unicode((fields.get("options") or ""), "UTF-8").encode(self.tool.getCharset()) 
+                job.JobOptions = self.databaseToUserCharset(fields.get("options") or "") 
                 job.JobDate = fields.get("jobdate")
                 job.JobHostName = fields.get("hostname")
Index: /pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- /pykota/trunk/pykota/storages/ldapstorage.py (revision 1777)
+++ /pykota/trunk/pykota/storages/ldapstorage.py (revision 1790)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.83  2004/10/07 21:14:28  jalet
+# Hopefully final fix for data encoding to and from the database
+#
 # Revision 1.82  2004/10/05 09:59:20  jalet
 # Restore compatibility with Python 2.1
@@ -592,5 +595,5 @@
             printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0)
             printer.uniqueMember = fields.get("uniqueMember", [])
-            printer.Description = unicode(fields.get("description", [""])[0], "UTF-8").encode(self.tool.getCharset()) 
+            printer.Description = self.databaseToUserCharset(fields.get("description", [""])[0]) 
             printer.Exists = 1
         return printer    
@@ -693,8 +696,8 @@
                     lastjob.JobPrice = None
                 lastjob.JobAction = fields.get("pykotaAction", [""])[0]
-                lastjob.JobFileName = unicode(fields.get("pykotaFileName", [""])[0], "UTF-8").encode(self.tool.getCharset()) 
-                lastjob.JobTitle = unicode(fields.get("pykotaTitle", [""])[0], "UTF-8").encode(self.tool.getCharset()) 
+                lastjob.JobFileName = self.databaseToUserCharset(fields.get("pykotaFileName", [""])[0]) 
+                lastjob.JobTitle = self.databaseToUserCharset(fields.get("pykotaTitle", [""])[0]) 
                 lastjob.JobCopies = int(fields.get("pykotaCopies", [0])[0])
-                lastjob.JobOptions = unicode(fields.get("pykotaOptions", [""])[0], "UTF-8").encode(self.tool.getCharset()) 
+                lastjob.JobOptions = self.databaseToUserCharset(fields.get("pykotaOptions", [""])[0]) 
                 lastjob.JobHostName = fields.get("pykotaHostName", [""])[0]
                 lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0]
@@ -769,5 +772,5 @@
                 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0)
                 printer.uniqueMember = fields.get("uniqueMember", [])
-                printer.Description = unicode(fields.get("description", [""])[0], "UTF-8").encode(self.tool.getCharset()) 
+                printer.Description = self.databaseToUserCharset(fields.get("description", [""])[0]) 
                 printer.Exists = 1
                 printers.append(printer)
@@ -981,5 +984,5 @@
         """Write the printer's description back into the storage."""
         fields = {
-                   "description" : unicode(str(printer.Description), self.tool.getCharset()).encode("UTF-8"), 
+                   "description" : self.userCharsetToDatabase(str(printer.Description)), 
                  }
         self.doModify(printer.ident, fields)
@@ -1080,8 +1083,8 @@
                    "pykotaPrinterPageCounter" : str(pagecounter),
                    "pykotaAction" : action,
-                   "pykotaFileName" : ((filename is None) and "None") or unicode(filename, self.tool.getCharset()).encode("UTF-8"), 
-                   "pykotaTitle" : ((title is None) and "None") or unicode(title, self.tool.getCharset()).encode("UTF-8"), 
+                   "pykotaFileName" : ((filename is None) and "None") or self.userCharsetToDatabase(filename), 
+                   "pykotaTitle" : ((title is None) and "None") or self.userCharsetToDatabase(title), 
                    "pykotaCopies" : str(copies), 
-                   "pykotaOptions" : ((options is None) and "None") or unicode(options, self.tool.getCharset()).encode("UTF-8"), 
+                   "pykotaOptions" : ((options is None) and "None") or self.userCharsetToDatabase(options), 
                    "pykotaHostName" : str(clienthost), 
                    "pykotaJobSizeBytes" : str(jobsizebytes),
@@ -1182,8 +1185,8 @@
                     job.JobPrice = None
                 job.JobAction = fields.get("pykotaAction", [""])[0]
-                job.JobFileName = unicode(fields.get("pykotaFileName", [""])[0], "UTF-8").encode(self.tool.getCharset()) 
-                job.JobTitle = unicode(fields.get("pykotaTitle", [""])[0], "UTF-8").encode(self.tool.getCharset()) 
+                job.JobFileName = self.databaseToUserCharset(fields.get("pykotaFileName", [""])[0]) 
+                job.JobTitle = self.databaseToUserCharset(fields.get("pykotaTitle", [""])[0]) 
                 job.JobCopies = int(fields.get("pykotaCopies", [0])[0])
-                job.JobOptions = unicode(fields.get("pykotaOptions", [""])[0], "UTF-8").encode(self.tool.getCharset()) 
+                job.JobOptions = self.databaseToUserCharset(fields.get("pykotaOptions", [""])[0]) 
                 job.JobHostName = fields.get("pykotaHostName", [""])[0]
                 job.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0]
Index: /pykota/trunk/pykota/storage.py
===================================================================
--- /pykota/trunk/pykota/storage.py (revision 1755)
+++ /pykota/trunk/pykota/storage.py (revision 1790)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.63  2004/10/07 21:14:28  jalet
+# Hopefully final fix for data encoding to and from the database
+#
 # Revision 1.62  2004/09/28 17:45:31  jalet
 # Added the --hardreset command line option to edpykota
@@ -685,4 +688,22 @@
         return gpquotas        
         
+    def databaseToUserCharset(self, text) :
+        """Converts from database format (UTF-8) to user's charset."""
+        if text is not None :
+            try :
+                return unicode(text, "UTF-8").encode(self.tool.getCharset()) 
+            except UnicodeError :    
+                pass
+        return text
+        
+    def userCharsetToDatabase(self, text) :
+        """Converts from user's charset to database format (UTF-8)."""
+        if text is not None :
+            try :
+                return unicode(text, self.tool.getCharset()).encode("UTF-8") 
+            except UnicodeError :    
+                pass
+        return text
+        
 def openConnection(pykotatool) :
     """Returns a connection handle to the appropriate Quota Storage Database."""
Index: /pykota/trunk/bin/dumpykota
===================================================================
--- /pykota/trunk/bin/dumpykota (revision 1789)
+++ /pykota/trunk/bin/dumpykota (revision 1790)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.12  2004/10/07 21:14:28  jalet
+# Hopefully final fix for data encoding to and from the database
+#
 # Revision 1.11  2004/10/07 14:35:40  jalet
 # Now edpykota refuses to launch if the user is not a PyKota administrator.
@@ -234,7 +237,10 @@
             x.entry()
             for i in range(len(entry)) :
-                value = entry[i]
-                strvalue = unicode(str(value), self.getCharset()).encode("UTF-8")
-                x.attribute(strvalue, type=type(value).__name__, name=headers[i])
+                value = str(entry[i])
+                try :
+                    value = unicode(value, self.getCharset()).encode("UTF-8")
+                except UnicodeError :    
+                    pass
+                x.attribute(value, type=type(value).__name__, name=headers[i])
             x._pop()    
         x._output(self.outfile)
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1789)
+++ /pykota/trunk/NEWS (revision 1790)
@@ -24,4 +24,6 @@
     - 1.20alpha22 :
     
+        - Hopefully final fix for data encoding charset.
+        
         - edpykota now refuse to work if the user is not a PyKota admin.
         
