- Timestamp:
- 02/18/06 11:56:29 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkusers
r2706 r2707 308 308 for i in range(nbtotal) : 309 309 entry = entries[i] 310 if description is not None : # NB : "" is allowed ! 311 entry.setDescription(description) 312 if limitby : 313 entry.setLimitBy(limitby) 310 311 # We need a transaction because we may have to create a record 312 # in the payments' table at the same time we modify the user's balance. 313 self.storage.beginTransaction() 314 try : 315 if description is not None : # NB : "" is allowed ! 316 entry.setDescription(description) 317 if limitby : 318 entry.setLimitBy(limitby) 319 320 if suffix == "User" : 321 if overcharge is not None : # NB : 0 is allowed ! 322 entry.setOverChargeFactor(overcharge) 314 323 315 if suffix == "User" :316 if overcharge is not None : # NB : 0 is allowed !317 entry.setOverChargeFactor(overcharge)318 319 entry.save()320 321 if suffix == "User":322 if balance :323 if balance.startswith("+") or balance.startswith("-") :324 newbalance = float(entry.AccountBalance or 0.0) + balancevalue325 newlifetimepaid = float(entry.LifeTimePaid or 0.0) + balancevalue326 entry.setAccountBalance(newbalance, newlifetimepaid, comment)327 else:328 diff = balancevalue - float(entry.AccountBalance or 0.0)329 newlifetimepaid = float(entry.LifeTimePaid or 0.0) + diff330 entry.setAccountBalance(balancevalue, newlifetimepaid, comment)331 332 for ugroup in usersgroups:333 if options["remove"] :334 ugroup.delUserFromGroup(entry)335 else :336 ugroup.addUserToGroup(entry)337 324 if suffix == "User" : 325 if balance : 326 if balance.startswith("+") or balance.startswith("-") : 327 newbalance = float(entry.AccountBalance or 0.0) + balancevalue 328 newlifetimepaid = float(entry.LifeTimePaid or 0.0) + balancevalue 329 entry.setAccountBalance(newbalance, newlifetimepaid, comment) 330 else : 331 diff = balancevalue - float(entry.AccountBalance or 0.0) 332 newlifetimepaid = float(entry.LifeTimePaid or 0.0) + diff 333 entry.setAccountBalance(balancevalue, newlifetimepaid, comment) 334 335 for ugroup in usersgroups : 336 if options["remove"] : 337 ugroup.delUserFromGroup(entry) 338 else : 339 ugroup.addUserToGroup(entry) 340 entry.save() 341 except : 342 self.storage.rollbackTransaction() 343 raise 344 else : 345 self.storage.commitTransaction() 346 338 347 percent = 100.0 * float(i) / float(nbtotal) 339 348 self.display("\r%.02f%%" % percent) -
pykota/trunk/pykota/storage.py
r2706 r2707 76 76 """Sets the user's account balance in case he pays more money.""" 77 77 diff = float(lifetimepaid or 0.0) - float(self.LifeTimePaid or 0.0) 78 self.parent.beginTransaction() 79 try : 80 self.parent.writeUserAccountBalance(self, balance, lifetimepaid) 81 self.parent.writeNewPayment(self, diff, comment) 82 except PyKotaStorageError, msg : 83 self.parent.rollbackTransaction() 84 raise PyKotaStorageError, msg 85 else : 86 self.parent.commitTransaction() 87 self.AccountBalance = balance 88 self.LifeTimePaid = lifetimepaid 78 self.AccountBalance = balance 79 self.LifeTimePaid = lifetimepaid 80 self.parent.writeNewPayment(self, diff, comment) 81 self.isDirty = True 89 82 90 83 def setLimitBy(self, limitby) : -
pykota/trunk/pykota/storages/ldapstorage.py
r2706 r2707 1048 1048 self.doModify(user.ident, newfields) 1049 1049 1050 newfields = { "pykotaBalance" : str(user.AccountBalance or 0.0), 1051 "pykotaLifeTimePaid" : str(user.LifeTimePaid or 0.0), 1052 } 1053 self.doModify(user.idbalance, newfields) 1054 1050 1055 def saveGroup(self, group) : 1051 1056 """Saves the group to the database in a single operation.""" … … 1096 1101 return self.doModify(user.idbalance, fields, flushcache=1) 1097 1102 1098 def writeUserAccountBalance(self, user, newbalance, newlifetimepaid=None) :1099 """Sets the new account balance and eventually new lifetime paid."""1100 fields = {1101 "pykotaBalance" : str(newbalance),1102 }1103 if newlifetimepaid is not None :1104 fields.update({ "pykotaLifeTimePaid" : str(newlifetimepaid) })1105 return self.doModify(user.idbalance, fields)1106 1107 1103 def writeNewPayment(self, user, amount, comment="") : 1108 1104 """Adds a new payment to the payments history.""" -
pykota/trunk/pykota/storages/sql.py
r2706 r2707 572 572 def saveUser(self, user) : 573 573 """Saves the user to the database in a single operation.""" 574 self.doModify("UPDATE users SET limitby=%s, email=%s, overcharge=%s, description=%s WHERE id=%s" \574 self.doModify("UPDATE users SET limitby=%s, balance=%s, lifetimepaid=%s, email=%s, overcharge=%s, description=%s WHERE id=%s" \ 575 575 % (self.doQuote(user.LimitBy or 'quota'), \ 576 self.doQuote(user.AccountBalance or 0.0), \ 577 self.doQuote(user.LifeTimePaid or 0.0), \ 576 578 self.doQuote(user.Email), \ 577 579 self.doQuote(user.OverCharge), \ … … 618 620 self.doModify("UPDATE users SET balance=balance - %s WHERE id=%s" % (self.doQuote(amount), self.doQuote(user.ident))) 619 621 620 def writeUserAccountBalance(self, user, newbalance, newlifetimepaid=None) :621 """Sets the new account balance and eventually new lifetime paid."""622 if newlifetimepaid is not None :623 self.doModify("UPDATE users SET balance=%s, lifetimepaid=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(newlifetimepaid), self.doQuote(user.ident)))624 else :625 self.doModify("UPDATE users SET balance=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(user.ident)))626 627 622 def writeNewPayment(self, user, amount, comment="") : 628 623 """Adds a new payment to the payments history."""