Changeset 1522 for pykota/trunk/pykota
- Timestamp:
- 06/06/04 00:03:50 (20 years ago)
- Location:
- pykota/trunk/pykota
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storage.py
r1520 r1522 22 22 # 23 23 # $Log$ 24 # Revision 1.54 2004/06/05 22:03:49 jalet 25 # Payments history is now stored in database 26 # 24 27 # Revision 1.53 2004/06/03 23:14:10 jalet 25 28 # Now stores the job's size in bytes in the database. … … 230 233 self.LifeTimePaid = None 231 234 self.Email = None 235 self.Payments = [] # TODO : maybe handle this smartly for SQL, for now just don't retrieve them 232 236 233 237 def consumeAccountBalance(self, amount) : … … 238 242 def setAccountBalance(self, balance, lifetimepaid) : 239 243 """Sets the user's account balance in case he pays more money.""" 240 self.parent.writeUserAccountBalance(self, balance, lifetimepaid) 241 self.AccountBalance = balance 242 self.LifeTimePaid = lifetimepaid 244 diff = float(lifetimepaid or 0.0) - float(self.LifeTimePaid or 0.0) 245 self.parent.beginTransaction() 246 try : 247 self.parent.writeUserAccountBalance(self, balance, lifetimepaid) 248 self.parent.writeNewPayment(self, diff) 249 except PyKotaStorageError, msg : 250 self.parent.rollbackTransaction() 251 raise PyKotaStorageError, msg 252 else : 253 self.parent.commitTransaction() 254 self.AccountBalance = balance 255 self.LifeTimePaid = lifetimepaid 243 256 244 257 def setLimitBy(self, limitby) : -
pykota/trunk/pykota/storages/ldapstorage.py
r1520 r1522 22 22 # 23 23 # $Log$ 24 # Revision 1.68 2004/06/05 22:03:50 jalet 25 # Payments history is now stored in database 26 # 24 27 # Revision 1.67 2004/06/03 23:14:10 jalet 25 28 # Now stores the job's size in bytes in the database. … … 257 260 import time 258 261 import md5 262 from mx import DateTime 259 263 260 264 from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageJob,StorageLastJob,StorageUserPQuota,StorageGroupPQuota … … 477 481 if user.LimitBy is not None : 478 482 user.LimitBy = user.LimitBy[0] 479 result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["balancerdn"], username), ["pykotaBalance", "pykotaLifeTimePaid" ], base=self.info["balancebase"])483 result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["balancerdn"], username), ["pykotaBalance", "pykotaLifeTimePaid", "pykotaPayments"], base=self.info["balancebase"]) 480 484 if result : 481 485 fields = result[0][1] … … 495 499 user.LifeTimePaid = float(user.LifeTimePaid[0]) 496 500 user.LifeTimePaid = user.LifeTimePaid or 0.0 501 user.Payments = [] 502 for payment in fields.get("pykotaPayments", []) : 503 (date, amount) = payment.split(" # ") 504 user.Payments.append((date, amount)) 497 505 user.Exists = 1 498 506 return user … … 944 952 return self.doModify(user.idbalance, fields) 945 953 954 def writeNewPayment(self, user, amount) : 955 """Adds a new payment to the payments history.""" 956 payments = [] 957 for payment in user.Payments : 958 payments.append("%s # %s" % (payment[0], str(payment[1]))) 959 payments.append("%s # %s" % (str(DateTime.now()), str(amount))) 960 fields = { 961 "pykotaPayments" : payments, 962 } 963 return self.doModify(user.idbalance, fields) 964 946 965 def writeLastJobSize(self, lastjob, jobsize, jobprice) : 947 966 """Sets the last job's size permanently.""" -
pykota/trunk/pykota/storages/sql.py
r1520 r1522 22 22 # 23 23 # $Log$ 24 # Revision 1.41 2004/06/05 22:03:50 jalet 25 # Payments history is now stored in database 26 # 24 27 # Revision 1.40 2004/06/03 23:14:11 jalet 25 28 # Now stores the job's size in bytes in the database. … … 342 345 self.doModify("UPDATE users SET balance=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(user.ident))) 343 346 347 def writeNewPayment(self, user, amount) : 348 """Adds a new payment to the payments history.""" 349 self.doModify("INSERT INTO payments (userid, amount) VALUES (%s, %s)" % (self.doQuote(user.ident), self.doQuote(amount))) 350 344 351 def writeLastJobSize(self, lastjob, jobsize, jobprice) : 345 352 """Sets the last job's size permanently.""" -
pykota/trunk/pykota/version.py
r1517 r1522 22 22 # 23 23 24 __version__ = "1.19alpha1 7_unofficial"24 __version__ = "1.19alpha18_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""