Show
Ignore:
Timestamp:
03/01/06 10:47:49 (18 years ago)
Author:
jerome
Message:

Optimized pkprinters like pkbcodes and edpykota.

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

Legend:

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

    r2765 r2768  
    887887        return groupsandquotas 
    888888         
    889     def addPrinter(self, printername) :         
    890         """Adds a printer to the quota storage, returns it.""" 
    891         printername = self.userCharsetToDatabase(printername) 
     889    def addPrinter(self, printer) : 
     890        """Adds a printer to the quota storage, returns the old value if it already exists.""" 
     891        oldentry = self.getPrinter(printer.Name) 
     892        if oldentry.Exists : 
     893            return oldentry # we return the existing entry 
     894        printername = self.userCharsetToDatabase(printer.Name) 
    892895        fields = { self.info["printerrdn"] : printername, 
    893896                   "objectClass" : ["pykotaObject", "pykotaPrinter"], 
    894897                   "cn" : printername, 
    895898                   "pykotaPrinterName" : printername, 
    896                    "pykotaPricePerPage" : "0.0", 
    897                    "pykotaPricePerJob" : "0.0", 
    898                    "pykotaMaxJobSize" : "0", 
    899                    "pykotaPassThrough" : "0", 
     899                   "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 
     900                   "pykotaMaxJobSize" : str(printer.MaxJobSize or 0), 
     901                   "description" : self.userCharsetToDatabase(printer.Description or ""), 
     902                   "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), 
     903                   "pykotaPricePerJob" : str(printer.PricePerJob or 0.0), 
    900904                 }  
    901905        dn = "%s=%s,%s" % (self.info["printerrdn"], printername, self.info["printerbase"]) 
    902906        self.doAdd(dn, fields) 
    903         return self.getPrinter(printername) 
     907        printer.isDirty = False 
     908        return None # the entry created doesn't need further modification 
    904909         
    905910    def addUser(self, user) :         
     
    10941099        fields = { 
    10951100                   "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 
    1096                    "pykotaMaxJobSize" : (printer.MaxJobSize and str(printer.MaxJobSize)) or "0", 
     1101                   "pykotaMaxJobSize" : str(printer.MaxJobSize or 0), 
    10971102                   "description" : self.userCharsetToDatabase(printer.Description or ""), 
    1098                    "pykotaPricePerPage" : str(printer.PricePerPage), 
    1099                    "pykotaPricePerJob" : str(printer.PricePerJob), 
     1103                   "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), 
     1104                   "pykotaPricePerJob" : str(printer.PricePerJob or 0.0), 
    11001105                 } 
    11011106        self.doModify(printer.ident, fields) 
  • pykota/trunk/pykota/storages/sql.py

    r2765 r2768  
    527527        return groupsandquotas 
    528528         
    529     def addPrinter(self, printername) :         
    530         """Adds a printer to the quota storage, returns it.""" 
    531         self.doModify("INSERT INTO printers (printername) VALUES (%s)" % self.doQuote(self.userCharsetToDatabase(printername))) 
    532         return self.getPrinter(printername) 
     529    def addPrinter(self, printer) :         
     530        """Adds a printer to the quota storage, returns the old value if it already exists.""" 
     531        try : 
     532            self.doModify("INSERT INTO printers (printername, passthrough, maxjobsize, description, priceperpage, priceperjob) VALUES (%s, %s, %s, %s, %s, %s)" \ 
     533                              % (self.doQuote(self.userCharsetToDatabase(printer.Name)), \ 
     534                                 self.doQuote((printer.PassThrough and "t") or "f"), \ 
     535                                 self.doQuote(printer.MaxJobSize or 0), \ 
     536                                 self.doQuote(self.userCharsetToDatabase(printer.Description)), \ 
     537                                 self.doQuote(printer.PricePerPage or 0.0), \ 
     538                                 self.doQuote(printer.PricePerJob or 0.0))) 
     539        except PyKotaStorageError :     
     540            # TODO : check if this is an error different from a duplicate insert 
     541            # return the existing entry which has to be modified 
     542            return self.getPrinter(printer.Name) 
     543        else :     
     544            printer.isDirty = False 
     545            return None # the entry created doesn't need further modification 
    533546         
    534547    def addBillingCode(self, bcode) : 
     
    626639        self.doModify("UPDATE printers SET passthrough=%s, maxjobsize=%s, description=%s, priceperpage=%s, priceperjob=%s WHERE id=%s" \ 
    627640                              % (self.doQuote((printer.PassThrough and "t") or "f"), \ 
    628                                  self.doQuote(printer.MaxJobSize), \ 
     641                                 self.doQuote(printer.MaxJobSize or 0), \ 
    629642                                 self.doQuote(self.userCharsetToDatabase(printer.Description)), \ 
    630                                  self.doQuote(printer.PricePerPage), \ 
    631                                  self.doQuote(printer.PricePerJob), \ 
     643                                 self.doQuote(printer.PricePerPage or 0.0), \ 
     644                                 self.doQuote(printer.PricePerJob or 0.0), \ 
    632645                                 self.doQuote(printer.ident))) 
    633646                                  
     
    852865        printerids = ", ".join(["%s" % self.doQuote(p.ident) for p in printers]) 
    853866        self.deleteInTransaction([  
    854                     "DELETE FROM printergroupsmembers WHERE groupid IN (%s) OR printerid IN (%s)" % printerids, 
     867                    "DELETE FROM printergroupsmembers WHERE groupid IN (%s) OR printerid IN (%s)" % (printerids, printerids), 
    855868                    "DELETE FROM jobhistory WHERE printerid IN (%s)" % printerids, 
    856869                    "DELETE FROM grouppquota WHERE printerid IN (%s)" % printerids,