Show
Ignore:
Timestamp:
02/23/06 11:58:05 (18 years ago)
Author:
jerome
Message:

Now manage print quota entries the way it should be done (c) (tm) !

Files:
1 modified

Legend:

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

    r2743 r2749  
    644644                       (self.doQuote(group.ident), self.doQuote(user.ident))) 
    645645             
    646     def addUserPQuota(self, user, printer) : 
     646    def addUserPQuota(self, upq) : 
    647647        """Initializes a user print quota on a printer.""" 
    648         self.doModify("INSERT INTO userpquota (userid, printerid) VALUES (%s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident))) 
    649         return self.getUserPQuota(user, printer) 
    650          
    651     def addGroupPQuota(self, group, printer) : 
     648        try : 
     649            self.doModify("INSERT INTO userpquota (userid, printerid, softlimit, hardlimit, warncount, datelimit, pagecounter, lifepagecounter, maxjobsize) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)" \ 
     650                              % (self.doQuote(upq.User.ident), \ 
     651                                 self.doQuote(upq.Printer.ident), \ 
     652                                 self.doQuote(upq.SoftLimit), \ 
     653                                 self.doQuote(upq.HardLimit), \ 
     654                                 self.doQuote(upq.WarnCount), \ 
     655                                 self.doQuote(upq.DateLimit), \ 
     656                                 self.doQuote(upq.PageCounter), \ 
     657                                 self.doQuote(upq.LifePageCounter), \ 
     658                                 self.doQuote(upq.MaxJobSize))) 
     659        except PyKotaStorageError :                          
     660            # TODO : check if this is an error different from a duplicate insert 
     661            # return the existing entry which has to be modified 
     662            return self.getUserPQuota(upq.User, upq.Printer) 
     663        else :     
     664            upq.isDirty = False 
     665            return None # the entry created doesn't need further modification 
     666         
     667    def addGroupPQuota(self, gpq) : 
    652668        """Initializes a group print quota on a printer.""" 
    653         self.doModify("INSERT INTO grouppquota (groupid, printerid) VALUES (%s, %s)" % (self.doQuote(group.ident), self.doQuote(printer.ident))) 
    654         return self.getGroupPQuota(group, printer) 
     669        try : 
     670            self.doModify("INSERT INTO grouppquota (groupid, printerid, softlimit, hardlimit, datelimit, maxjobsize) VALUES (%s, %s, %s, %s, %s, %s)" \ 
     671                              % (self.doQuote(gpq.Group.ident), \ 
     672                                 self.doQuote(gpq.Printer.ident), \ 
     673                                 self.doQuote(gpq.SoftLimit), \ 
     674                                 self.doQuote(gpq.HardLimit), \ 
     675                                 self.doQuote(gpq.DateLimit), \ 
     676                                 self.doQuote(gpq.MaxJobSize))) 
     677        except PyKotaStorageError :                          
     678            # TODO : check if this is an error different from a duplicate insert 
     679            # return the existing entry which has to be modified 
     680            return self.getGroupPQuota(gpq.Group, gpq.Printer) 
     681        else :     
     682            gpq.isDirty = False 
     683            return None # the entry created doesn't need further modification 
    655684         
    656685    def savePrinter(self, printer) :     
     
    738767    def saveUserPQuota(self, userpquota) : 
    739768        """Saves an user print quota entry.""" 
    740         self.doModify("UPDATE userpquota SET softlimit=%s, hardlimit=%s, warncount=%s, datelimit=%s, pagecounter=%s, lifepagecounter=%s WHERE id=%s" \ 
     769        self.doModify("UPDATE userpquota SET softlimit=%s, hardlimit=%s, warncount=%s, datelimit=%s, pagecounter=%s, lifepagecounter=%s, maxjobsize=%s WHERE id=%s" \ 
    741770                              % (self.doQuote(userpquota.SoftLimit), \ 
    742771                                 self.doQuote(userpquota.HardLimit), \ 
     
    745774                                 self.doQuote(userpquota.PageCounter), \ 
    746775                                 self.doQuote(userpquota.LifePageCounter), \ 
     776                                 self.doQuote(userpquota.MaxJobSize), \ 
    747777                                 self.doQuote(userpquota.ident))) 
    748778         
     
    843873            self.doModify(q) 
    844874             
     875    def deleteManyUserPQuotas(self, printers, users) :         
     876        """Deletes many user print quota entries.""" 
     877        printerids = ", ".join(["%s" % self.doQuote(p.ident) for p in printers]) 
     878        userids = ", ".join(["%s" % self.doQuote(u.ident) for u in users]) 
     879        for q in [  
     880                    "DELETE FROM jobhistory WHERE userid IN (%s) AND printerid IN (%s)" \ 
     881                                 % (userids, printerids), 
     882                    "DELETE FROM userpquota WHERE userid IN (%s) AND printerid IN (%s)" \ 
     883                                 % (userids, printerids), 
     884                  ] : 
     885            self.doModify(q) 
     886             
     887    def deleteManyGroupPQuotas(self, printers, groups) : 
     888        """Deletes many group print quota entries.""" 
     889        printerids = ", ".join(["%s" % self.doQuote(p.ident) for p in printers]) 
     890        groupids = ", ".join(["%s" % self.doQuote(g.ident) for g in groups]) 
     891        for q in [  
     892                    "DELETE FROM grouppquota WHERE groupid IN (%s) AND printerid IN (%s)" \ 
     893                                 % (groupids, printerids), 
     894                  ] : 
     895            self.doModify(q) 
     896         
    845897    def deleteUserPQuota(self, upquota) :     
    846898        """Completely deletes an user print quota entry from the database."""