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

Should be ok now.

Files:
1 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)