Index: pykota/trunk/pykota/storages/pgstorage.py
===================================================================
--- pykota/trunk/pykota/storages/pgstorage.py (revision 1228)
+++ pykota/trunk/pykota/storages/pgstorage.py (revision 1240)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.25  2003/12/27 16:49:25  uid67467
+# Should be ok now.
+#
 # Revision 1.24  2003/11/29 22:02:14  jalet
 # Don't try to retrieve the user print quota information if current printer
@@ -392,4 +395,15 @@
         return groupsandquotas
         
+    def getParentPrinters(self, printer) :    
+        """Get all the printer groups this printer is a member of."""
+        pgroups = []
+        result = self.doSearch("SELECT printername FROM printergroupsmembers JOIN printers ON groupid=id WHERE printerid=%s;" % self.doQuote(printer.ident))
+        if result :
+            for record in result :
+                parentprinter = self.getPrinter(record.get("printername"))
+                if parentprinter.Exists :
+                    pgroups.append(parentprinter)
+        return pgroups
+        
     def addPrinter(self, printername) :        
         """Adds a printer to the quota storage, returns it."""
@@ -468,5 +482,5 @@
                 self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options)))
             else :    
-                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, filename, title, copies, options) VALUES (%s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options)))
+                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, filename, title, copies, options) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options)))
         else :        
             # here we explicitly want to reset jobsize to NULL if needed
Index: pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- pykota/trunk/pykota/storages/ldapstorage.py (revision 1228)
+++ pykota/trunk/pykota/storages/ldapstorage.py (revision 1240)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.41  2003/12/27 16:49:25  uid67467
+# Should be ok now.
+#
 # Revision 1.40  2003/11/29 22:02:14  jalet
 # Don't try to retrieve the user print quota information if current printer
@@ -166,4 +169,5 @@
 #
 
+import types
 import time
 import md5
@@ -211,4 +215,14 @@
         return md5.md5("%s" % time.time()).hexdigest()
         
+    def normalizeFields(self, fields) :    
+        """Ensure all items are lists."""
+        for (k, v) in fields.items() :
+            if type(v) not in (types.TupleType, types.ListType) :
+                if not v :
+                    del fields[k]
+                else :    
+                    fields[k] = [ v ]
+        return fields        
+        
     def beginTransaction(self) :    
         """Starts a transaction."""
@@ -237,4 +251,5 @@
     def doAdd(self, dn, fields) :
         """Adds an entry in the LDAP directory."""
+        fields = self.normalizeFields(fields)
         try :
             self.tool.logdebug("QUERY : ADD(%s, %s)" % (dn, str(fields)))
@@ -255,4 +270,5 @@
     def doModify(self, dn, fields, ignoreold=1) :
         """Modifies an entry in the LDAP directory."""
+        fields = self.normalizeFields(fields)
         try :
             oldentry = self.doSearch("objectClass=*", base=dn, scope=ldap.SCOPE_BASE)
@@ -545,4 +561,15 @@
         return groupsandquotas
         
+    def getParentPrinters(self, printer) :    
+        """Get all the printer groups this printer is a member of."""
+        pgroups = []
+        result = self.doSearch("(&(objectClass=pykotaPrinter)(uniqueMember=%s))" % printer.ident, ["pykotaPrinterName"], base=self.info["printerbase"])
+        if result :
+            for (printerid, fields) in result :
+                parentprinter = self.getPrinter(fields.get("pykotaPrinterName")[0])
+                if parentprinter.Exists :
+                    pgroups.append(parentprinter)
+        return pgroups
+        
     def addPrinter(self, printername) :        
         """Adds a printer to the quota storage, returns it."""
@@ -679,5 +706,5 @@
         """Sets the date limit permanently for a user print quota."""
         fields = {
-                   "pykotaDateLimit" : "%04i-%02i-%02i %02i:%02i:%02i" % (datelimit.year, datelimit.month, datelimit.day, datelimit.hour, datelimit.minute, datelimit.second),
+                   "pykotaDateLimit" : datelimit,
                  }
         return self.doModify(userpquota.ident, fields)
@@ -686,5 +713,5 @@
         """Sets the date limit permanently for a group print quota."""
         fields = {
-                   "pykotaDateLimit" : "%04i-%02i-%02i %02i:%02i:%02i" % (datelimit.year, datelimit.month, datelimit.day, datelimit.hour, datelimit.minute, datelimit.second),
+                   "pykotaDateLimit" : datelimit,
                  }
         return self.doModify(grouppquota.ident, fields)
