Changeset 925 for pykota/trunk/pykota
- Timestamp:
- 04/16/03 10:53:14 (21 years ago)
- Location:
- pykota/trunk/pykota
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/sql.py
r921 r925 21 21 # 22 22 # $Log$ 23 # Revision 1.26 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 # 23 28 # Revision 1.25 2003/04/15 21:58:33 jalet 24 29 # edpykota now accepts a --delete option. … … 234 239 return 235 240 241 def getUserLimitBy(self, userid) : 242 """Returns the way in which user printing is limited.""" 243 result = self.doQuery("SELECT limitby FROM users WHERE id=%s" % self.doQuote(userid)) 244 try : 245 return self.doParseResult(result)[0]["limitby"] 246 except TypeError : # Not found 247 return 248 249 def getGroupLimitBy(self, groupid) : 250 """Returns the way in which group printing is limited.""" 251 result = self.doQuery("SELECT limitby FROM groups WHERE id=%s" % self.doQuote(groupid)) 252 try : 253 return self.doParseResult(result)[0]["limitby"] 254 except TypeError : # Not found 255 return 256 236 257 def setUserBalance(self, userid, balance) : 237 258 """Sets the account balance for a given user to a fixed value.""" -
pykota/trunk/pykota/tool.py
r915 r925 21 21 # 22 22 # $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 # 23 28 # Revision 1.31 2003/04/15 11:30:57 jalet 24 29 # More work done on money print charging. … … 286 291 printerid = self.storage.getPrinterId(printername) 287 292 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)) 294 303 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 : 304 308 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" 305 316 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" 309 327 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 : 320 344 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 : 322 351 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 327 354 action = "ALLOW" 328 else :329 action = "DENY"330 else :331 # Both are unset, no quota, i.e. accounting only332 action = "ALLOW"333 355 return action 334 356