Show
Ignore:
Timestamp:
12/27/03 17:49:25 (20 years ago)
Author:
uid67467
Message:

Should be ok now.

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

Legend:

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

    r1228 r1240  
    2222# 
    2323# $Log$ 
     24# Revision 1.41  2003/12/27 16:49:25  uid67467 
     25# Should be ok now. 
     26# 
    2427# Revision 1.40  2003/11/29 22:02:14  jalet 
    2528# Don't try to retrieve the user print quota information if current printer 
     
    166169# 
    167170 
     171import types 
    168172import time 
    169173import md5 
     
    211215        return md5.md5("%s" % time.time()).hexdigest() 
    212216         
     217    def normalizeFields(self, fields) :     
     218        """Ensure all items are lists.""" 
     219        for (k, v) in fields.items() : 
     220            if type(v) not in (types.TupleType, types.ListType) : 
     221                if not v : 
     222                    del fields[k] 
     223                else :     
     224                    fields[k] = [ v ] 
     225        return fields         
     226         
    213227    def beginTransaction(self) :     
    214228        """Starts a transaction.""" 
     
    237251    def doAdd(self, dn, fields) : 
    238252        """Adds an entry in the LDAP directory.""" 
     253        fields = self.normalizeFields(fields) 
    239254        try : 
    240255            self.tool.logdebug("QUERY : ADD(%s, %s)" % (dn, str(fields))) 
     
    255270    def doModify(self, dn, fields, ignoreold=1) : 
    256271        """Modifies an entry in the LDAP directory.""" 
     272        fields = self.normalizeFields(fields) 
    257273        try : 
    258274            oldentry = self.doSearch("objectClass=*", base=dn, scope=ldap.SCOPE_BASE) 
     
    545561        return groupsandquotas 
    546562         
     563    def getParentPrinters(self, printer) :     
     564        """Get all the printer groups this printer is a member of.""" 
     565        pgroups = [] 
     566        result = self.doSearch("(&(objectClass=pykotaPrinter)(uniqueMember=%s))" % printer.ident, ["pykotaPrinterName"], base=self.info["printerbase"]) 
     567        if result : 
     568            for (printerid, fields) in result : 
     569                parentprinter = self.getPrinter(fields.get("pykotaPrinterName")[0]) 
     570                if parentprinter.Exists : 
     571                    pgroups.append(parentprinter) 
     572        return pgroups 
     573         
    547574    def addPrinter(self, printername) :         
    548575        """Adds a printer to the quota storage, returns it.""" 
     
    679706        """Sets the date limit permanently for a user print quota.""" 
    680707        fields = { 
    681                    "pykotaDateLimit" : "%04i-%02i-%02i %02i:%02i:%02i" % (datelimit.year, datelimit.month, datelimit.day, datelimit.hour, datelimit.minute, datelimit.second), 
     708                   "pykotaDateLimit" : datelimit, 
    682709                 } 
    683710        return self.doModify(userpquota.ident, fields) 
     
    686713        """Sets the date limit permanently for a group print quota.""" 
    687714        fields = { 
    688                    "pykotaDateLimit" : "%04i-%02i-%02i %02i:%02i:%02i" % (datelimit.year, datelimit.month, datelimit.day, datelimit.hour, datelimit.minute, datelimit.second), 
     715                   "pykotaDateLimit" : datelimit, 
    689716                 } 
    690717        return self.doModify(grouppquota.ident, fields) 
  • pykota/trunk/pykota/storages/pgstorage.py

    r1228 r1240  
    2222# 
    2323# $Log$ 
     24# Revision 1.25  2003/12/27 16:49:25  uid67467 
     25# Should be ok now. 
     26# 
    2427# Revision 1.24  2003/11/29 22:02:14  jalet 
    2528# Don't try to retrieve the user print quota information if current printer 
     
    392395        return groupsandquotas 
    393396         
     397    def getParentPrinters(self, printer) :     
     398        """Get all the printer groups this printer is a member of.""" 
     399        pgroups = [] 
     400        result = self.doSearch("SELECT printername FROM printergroupsmembers JOIN printers ON groupid=id WHERE printerid=%s;" % self.doQuote(printer.ident)) 
     401        if result : 
     402            for record in result : 
     403                parentprinter = self.getPrinter(record.get("printername")) 
     404                if parentprinter.Exists : 
     405                    pgroups.append(parentprinter) 
     406        return pgroups 
     407         
    394408    def addPrinter(self, printername) :         
    395409        """Adds a printer to the quota storage, returns it.""" 
     
    468482                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))) 
    469483            else :     
    470                 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))) 
     484                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))) 
    471485        else :         
    472486            # here we explicitly want to reset jobsize to NULL if needed