Show
Ignore:
Timestamp:
04/16/03 10:53:14 (21 years ago)
Author:
jalet
Message:

Printing can now be limited either by user's account balance or by
page quota (the default). Quota report doesn't include account balance
yet, though.

Files:
1 modified

Legend:

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

    r915 r925  
    2121# 
    2222# $Log$ 
     23# Revision 1.32  2003/04/16 08:53:14  jalet 
     24# Printing can now be limited either by user's account balance or by 
     25# page quota (the default). Quota report doesn't include account balance 
     26# yet, though. 
     27# 
    2328# Revision 1.31  2003/04/15 11:30:57  jalet 
    2429# More work done on money print charging. 
     
    286291        printerid = self.storage.getPrinterId(printername) 
    287292        userid = self.storage.getUserId(username) 
    288         quota = self.storage.getUserPQuota(userid, printerid) 
    289         if quota is None : 
    290             # Unknown user or printer or combination 
    291             policy = self.config.getPrinterPolicy(printername) 
    292             if policy in [None, "ALLOW"] : 
    293                 action = "POLICY_ALLOW" 
     293        limitby = self.storage.getUserLimitBy(userid) 
     294        if limitby == "balance" :  
     295            balance = self.storage.getUserBalance(userid) 
     296            if balance is None : 
     297                policy = self.config.getPrinterPolicy(printername) 
     298                if policy in [None, "ALLOW"] : 
     299                    action = "POLICY_ALLOW" 
     300                else :     
     301                    action = "POLICY_DENY" 
     302                self.logger.log_message(_("Unable to find user %s's account balance, applying default policy (%s) for printer %s") % (username, action, printername)) 
    294303            else :     
    295                 action = "POLICY_DENY" 
    296             self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (username, printername, action)) 
    297         else :     
    298             pagecounter = quota["pagecounter"] 
    299             softlimit = quota["softlimit"] 
    300             hardlimit = quota["hardlimit"] 
    301             datelimit = quota["datelimit"] 
    302             if softlimit is not None : 
    303                 if pagecounter < softlimit : 
     304                # TODO : there's no warning (no account balance soft limit) 
     305                if balance <= 0.0 : 
     306                    action = "DENY" 
     307                else :     
    304308                    action = "ALLOW" 
     309        else : 
     310            quota = self.storage.getUserPQuota(userid, printerid) 
     311            if quota is None : 
     312                # Unknown user or printer or combination 
     313                policy = self.config.getPrinterPolicy(printername) 
     314                if policy in [None, "ALLOW"] : 
     315                    action = "POLICY_ALLOW" 
    305316                else :     
    306                     if hardlimit is None : 
    307                         # only a soft limit, this is equivalent to having only a hard limit 
    308                         action = "DENY" 
     317                    action = "POLICY_DENY" 
     318                self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (username, printername, action)) 
     319            else :     
     320                pagecounter = quota["pagecounter"] 
     321                softlimit = quota["softlimit"] 
     322                hardlimit = quota["hardlimit"] 
     323                datelimit = quota["datelimit"] 
     324                if softlimit is not None : 
     325                    if pagecounter < softlimit : 
     326                        action = "ALLOW" 
    309327                    else :     
    310                         if softlimit <= pagecounter < hardlimit :     
    311                             now = DateTime.now() 
    312                             if datelimit is not None : 
    313                                 datelimit = DateTime.ISO.ParseDateTime(datelimit) 
    314                             else : 
    315                                 datelimit = now + self.config.getGraceDelay(printername) 
    316                                 self.storage.setUserDateLimit(userid, printerid, datelimit) 
    317                             if now < datelimit : 
    318                                 action = "WARN" 
    319                             else :     
     328                        if hardlimit is None : 
     329                            # only a soft limit, this is equivalent to having only a hard limit 
     330                            action = "DENY" 
     331                        else :     
     332                            if softlimit <= pagecounter < hardlimit :     
     333                                now = DateTime.now() 
     334                                if datelimit is not None : 
     335                                    datelimit = DateTime.ISO.ParseDateTime(datelimit) 
     336                                else : 
     337                                    datelimit = now + self.config.getGraceDelay(printername) 
     338                                    self.storage.setUserDateLimit(userid, printerid, datelimit) 
     339                                if now < datelimit : 
     340                                    action = "WARN" 
     341                                else :     
     342                                    action = "DENY" 
     343                            else :          
    320344                                action = "DENY" 
    321                         else :          
     345                else :         
     346                    if hardlimit is not None : 
     347                        # no soft limit, only a hard one. 
     348                        if pagecounter < hardlimit : 
     349                            action = "ALLOW" 
     350                        else :       
    322351                            action = "DENY" 
    323             else :         
    324                 if hardlimit is not None : 
    325                     # no soft limit, only a hard one. 
    326                     if pagecounter < hardlimit : 
     352                    else : 
     353                        # Both are unset, no quota, i.e. accounting only 
    327354                        action = "ALLOW" 
    328                     else :       
    329                         action = "DENY" 
    330                 else : 
    331                     # Both are unset, no quota, i.e. accounting only 
    332                     action = "ALLOW" 
    333355        return action 
    334356