Changeset 2686 for pykota/trunk/pykota

Show
Ignore:
Timestamp:
02/12/06 13:32:53 (18 years ago)
Author:
jerome
Message:

Modified pkprinters to improve speed just like I did for pkbcodes earlier.
edpykota had to be modified as well to use the new printer API.
The time spent to modify printers has been almost halved.

Location:
pykota/trunk/pykota
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storage.py

    r2676 r2686  
    164164            raise AttributeError, name 
    165165             
     166    def save(self) :     
     167        """Saves the billing code to disk in a single operation.""" 
     168        if self.isDirty : 
     169            self.parent.savePrinter(self) 
     170            self.isDirty = False 
     171             
    166172    def addJobToHistory(self, jobid, user, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None, jobpages=None, jobbilling=None, precomputedsize=None, precomputedprice=None) : 
    167173        """Adds a job to the printer's history.""" 
     
    190196        else :     
    191197            self.PricePerJob = float(priceperjob) 
    192         self.parent.writePrinterPrices(self) 
     198        self.isDirty = True     
    193199         
    194200    def setDescription(self, description=None) : 
     
    198204        else :     
    199205            self.Description = str(description) 
    200         self.parent.writePrinterDescription(self) 
     206        self.isDirty = True     
     207         
     208    def setPassThrough(self, passthrough) : 
     209        """Sets the printer's passthrough mode.""" 
     210        self.PassThrough = passthrough 
     211        self.isDirty = True 
     212         
     213    def setMaxJobSize(self, maxjobsize) : 
     214        """Sets the printer's maximal job size.""" 
     215        self.MaxJobSize = maxjobsize 
     216        self.isDirty = True 
    201217         
    202218    def delete(self) :     
     
    218234                    if v.Printer.Name == self.Name : 
    219235                        self.parent.flushEntry("GROUPPQUOTAS", "%s@%s" % (v.Group.Name, v.Printer.Name)) 
    220             self.Exists = 0     
     236            self.isDirty = False             
     237            self.Exists = False 
    221238         
    222239class StorageUserPQuota(StorageObject) : 
     
    453470        self.parent.deleteBillingCode(self) 
    454471        self.parent.flushEntry("BILLINGCODES", self.BillingCode) 
     472        self.isDirty = False 
    455473        self.Exists = False 
    456         self.isDirty = False 
    457474         
    458475    def reset(self, balance=0.0, pagecounter=0) :     
    459476        """Resets the pagecounter and balance for this billing code.""" 
    460         if self.Balance != balance : 
    461             self.Balance = balance 
    462             self.isDirty = True 
    463         if self.PageCounter != pagecounter : 
    464             self.PageCounter = pagecounter 
    465             self.isDirty = True 
     477        self.Balance = balance 
     478        self.PageCounter = pagecounter 
     479        self.isDirty = True 
    466480         
    467481    def setDescription(self, description=None) : 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2680 r2686  
    10171017        return self.getGroupPQuota(group, printer) 
    10181018         
    1019     def writePrinterPrices(self, printer) :     
    1020         """Write the printer's prices back into the storage.""" 
     1019    def savePrinter(self, printer) :     
     1020        """Saves the printer to the database in a single operation.""" 
    10211021        fields = { 
     1022                   "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 
     1023                   "pykotaMaxJobSize" : (printer.MaxJobSize and str(printer.MaxJobSize)) or "0", 
     1024                   "description" : self.userCharsetToDatabase(printer.Description or ""), 
    10221025                   "pykotaPricePerPage" : str(printer.PricePerPage), 
    10231026                   "pykotaPricePerJob" : str(printer.PricePerJob), 
    1024                  } 
    1025         self.doModify(printer.ident, fields) 
    1026          
    1027     def writePrinterDescription(self, printer) :     
    1028         """Write the printer's description back into the storage.""" 
    1029         fields = { 
    1030                    "description" : self.userCharsetToDatabase(printer.Description or ""), 
    1031                  } 
    1032         if fields["description"] : 
    1033             self.doModify(printer.ident, fields) 
    1034              
    1035     def setPrinterMaxJobSize(self, printer, maxjobsize) :      
    1036         """Write the printer's maxjobsize attribute.""" 
    1037         fields = { 
    1038                    "pykotaMaxJobSize" : (maxjobsize and str(maxjobsize)) or "0", 
    1039                  } 
    1040         self.doModify(printer.ident, fields) 
    1041          
    1042     def setPrinterPassThroughMode(self, printer, passthrough) : 
    1043         """Write the printer's passthrough attribute.""" 
    1044         fields = { 
    1045                    "pykotaPassThrough" : (passthrough and "t") or "f", 
    10461027                 } 
    10471028        self.doModify(printer.ident, fields) 
  • pykota/trunk/pykota/storages/sql.py

    r2678 r2686  
    547547        return self.getGroupPQuota(group, printer) 
    548548         
    549     def writePrinterPrices(self, printer) :     
    550         """Write the printer's prices back into the storage.""" 
    551         self.doModify("UPDATE printers SET priceperpage=%s, priceperjob=%s WHERE id=%s" % (self.doQuote(printer.PricePerPage), self.doQuote(printer.PricePerJob), self.doQuote(printer.ident))) 
    552          
    553     def writePrinterDescription(self, printer) :     
    554         """Write the printer's description back into the storage.""" 
    555         description = self.userCharsetToDatabase(printer.Description) 
    556         self.doModify("UPDATE printers SET description=%s WHERE id=%s" % (self.doQuote(description), self.doQuote(printer.ident))) 
    557          
    558     def setPrinterMaxJobSize(self, printer, maxjobsize) :      
    559         """Write the printer's maxjobsize attribute.""" 
    560         self.doModify("UPDATE printers SET maxjobsize=%s WHERE id=%s" % (self.doQuote(maxjobsize), self.doQuote(printer.ident))) 
    561          
    562     def setPrinterPassThroughMode(self, printer, passthrough) : 
    563         """Write the printer's passthrough attribute.""" 
    564         self.doModify("UPDATE printers SET passthrough=%s WHERE id=%s" % (self.doQuote((passthrough and "t") or "f"), self.doQuote(printer.ident))) 
     549    def savePrinter(self, printer) :     
     550        """Saves the printer to the database in a single operation.""" 
     551        self.doModify("UPDATE printers SET passthrough=%s, maxjobsize=%s, description=%s, priceperpage=%s, priceperjob=%s WHERE id=%s" \ 
     552                              % (self.doQuote((printer.PassThrough and "t") or "f"), \ 
     553                                 self.doQuote(printer.MaxJobSize), \ 
     554                                 self.doQuote(self.userCharsetToDatabase(printer.Description)), \ 
     555                                 self.doQuote(printer.PricePerPage), \ 
     556                                 self.doQuote(printer.PricePerJob), \ 
     557                                 self.doQuote(printer.ident))) 
    565558         
    566559    def writeUserOverCharge(self, user, factor) :