Changeset 2375

Show
Ignore:
Timestamp:
07/18/05 18:52:19 (19 years ago)
Author:
jerome
Message:

More work done on LDAP + billing codes.

Files:
1 modified

Legend:

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

    r2373 r2375  
    846846        """Write the printer's description back into the storage.""" 
    847847        fields = { 
    848                    "description" : self.userCharsetToDatabase(str(printer.Description)),  
    849                  } 
    850         self.doModify(printer.ident, fields) 
     848                   "description" : self.userCharsetToDatabase(printer.Description or ""), 
     849                 } 
     850        if fields["description"] : 
     851            self.doModify(printer.ident, fields) 
    851852         
    852853    def writeUserOverCharge(self, user, factor) : 
     
    13691370        """Extracts billing code information given its label : returns first matching billing code.""" 
    13701371        code = StorageBillingCode(self, label) 
    1371         result = self.doSearch("(&(objectClass=pykotaBilling)(pykotaBillingCode=%s))" % label, ["pykotaBillingCode", "pykotaBalance", "pykotaPageCounter", "description"], base=self.info["billingcodebase"]) 
     1372        ulabel = self.userCharsetToDatabase(label) 
     1373        result = self.doSearch("(&(objectClass=pykotaBilling)(pykotaBillingCode=%s))" % ulabel, ["pykotaBillingCode", "pykotaBalance", "pykotaPageCounter", "description"], base=self.info["billingcodebase"]) 
    13721374        if result : 
    13731375            fields = result[0][1]       # take only first matching code, ignore the rest 
    13741376            code.ident = result[0][0] 
    1375             code.BillingCode = self.databaseToUserCharset(fields.get("pykotaBillingCode", [self.userCharsetToDatabase(label)])[0]) 
     1377            code.BillingCode = self.databaseToUserCharset(fields.get("pykotaBillingCode", [ulabel])[0]) 
    13761378            code.PageCounter = int(fields.get("pykotaPageCounter", [0])[0]) 
    13771379            code.Balance = float(fields.get("pykotaBalance", [0.0])[0]) 
     
    13791381            code.Exists = 1 
    13801382        return code     
    1381              
    1382 # def getBillingCodeFromBackend(self, label) :         
     1383         
     1384    def addBillingCode(self, label) : 
     1385        """Adds a billing code to the quota storage, returns it.""" 
     1386        uuid = self.genUUID() 
     1387        dn = "cn=%s,%s" % (uuid, self.info["billingcodebase"]) 
     1388        fields = { "objectClass" : ["pykotaObject", "pykotaBilling"], 
     1389                   "cn" : uuid, 
     1390                   "pykotaBillingCode" : self.userCharsetToDatabase(label), 
     1391                   "pykotaPageCounter" : "0", 
     1392                   "pykotaBalance" : "0.0", 
     1393                 }  
     1394        self.doAdd(dn, fields) 
     1395        return self.getBillingCode(label) 
     1396         
     1397    def writeBillingCodeDescription(self, code) : 
     1398        """Sets the new description for a billing code.""" 
     1399        fields = { 
     1400                   "description" : self.userCharsetToDatabase(code.Description or ""),  
     1401                 } 
     1402        if fields["description"] : 
     1403            self.doModify(code.ident, fields) 
     1404             
    13831405# def getMatchingBillingCodes(self, billingcodepattern) : 
    1384 # def addBillingCode(self, label) :         
    13851406# def writeBillingCodeDescription(self, code) : 
    13861407# def setBillingCodeValues(self, code, newbalance, newpagecounter) :