Changeset 3056
- Timestamp:
- 11/13/06 23:24:01 (18 years ago)
- Location:
- pykota/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/cgi-bin/printquota.cgi
r3055 r3056 210 210 billingcode = None 211 211 self.report = ["<h2>%s</h2>" % _("History")] 212 history = self.storage.retrieveHistory(user , printer, hostname,billingcode, end=datelimit)212 history = self.storage.retrieveHistory(user=user, printer=printer, hostname=hostname, billingcode=billingcode, end=datelimit) 213 213 if not history : 214 214 self.report.append("<h3>%s</h3>" % _("Empty")) -
pykota/trunk/pykota/storage.py
r3050 r3056 23 23 # 24 24 25 """This module is the database abstraction layer for PyKota.""" 26 25 27 import os 26 28 import imp … … 36 38 __str__ = __repr__ 37 39 40 38 41 class StorageObject : 39 42 """Object present in the database.""" … … 57 60 getattr(self.parent, "save%s" % self.__class__.__name__[7:])(self) 58 61 self.isDirty = False 62 59 63 60 64 class StorageUser(StorageObject) : … … 124 128 self.isDirty = False 125 129 130 def refund(self, amount) : 131 """Refunds a number of credits to an user.""" 132 self.consumeAccountBalance(-amount) 133 134 126 135 class StorageGroup(StorageObject) : 127 136 """User class.""" … … 161 170 self.Exists = False 162 171 self.isDirty = False 172 163 173 164 174 class StoragePrinter(StorageObject) : … … 236 246 self.Exists = False 237 247 self.isDirty = False 248 238 249 239 250 class StorageUserPQuota(StorageObject) : … … 360 371 self.isDirty = False 361 372 373 def refund(self, nbpages) : 374 """Refunds a number of pages to an user on a particular printer.""" 375 self.parent.increaseUserPQuotaPagesCounters(self, -nbpages) 376 self.PageCounter = int(self.PageCounter or 0) - nbpages 377 self.LifePageCounter = int(self.LifePageCounter or 0) - nbpages 378 379 362 380 class StorageGroupPQuota(StorageObject) : 363 381 """Group Print Quota class.""" … … 427 445 self.Exists = False 428 446 self.isDirty = False 447 429 448 430 449 class StorageJob(StorageObject) : … … 462 481 else : 463 482 raise AttributeError, name 483 484 def refund(self) : 485 """Refund a particular print job.""" 486 if (not self.JobSize) or (self.JobAction in ("DENY", "REFUND")) : 487 return 488 self.parent.beginTransaction() 489 try : 490 if self.JobBillingCode : 491 bcode = self.parent.getBillingCode(self.JobBillingCode) 492 bcode.refund(self.JobSize, self.JobPrice) 493 494 if self.User.Exists : 495 self.User.refund(self.JobPrice) 496 if self.Printer.Exists : 497 upq = self.parent.getUserPQuota(self.User, self.Printer) 498 if upq.Exists : 499 upq.refund(self.JobSize) 500 self.parent.refundJob(self.ident) 501 except : 502 self.parent.rollbackTransaction() 503 raise 504 else : 505 self.parent.commitTransaction() 506 464 507 465 508 class StorageLastJob(StorageJob) : … … 469 512 self.PrinterName = printer.Name # not needed 470 513 self.Printer = printer 514 471 515 472 516 class StorageBillingCode(StorageObject) : … … 494 538 """Consumes some pages and credits for this billing code.""" 495 539 if pages : 496 self.parent.consumeBillingCode(self, pages, price) 497 self.PageCounter += pages 498 self.Balance -= price 540 self.parent.consumeBillingCode(self, pages, price) 541 self.PageCounter += pages 542 self.Balance -= price 543 544 def refund(self, pages, price) : 545 """Refunds a particular billing code.""" 546 self.consume(-pages, -price) 547 499 548 500 549 class BaseStorage : -
pykota/trunk/pykota/storages/ldapstorage.py
r2953 r3056 1303 1303 self.doModify(pgroup.ident, fields) 1304 1304 1305 def retrieveHistory(self, user=None, printer=None, hostname=None, billingcode=None, limit=100, start=None, end=None) :1305 def retrieveHistory(self, user=None, printer=None, hostname=None, billingcode=None, jobid=None, limit=100, start=None, end=None) : 1306 1306 """Retrieves all print jobs for user on printer (or all) between start and end date, limited to first 100 results.""" 1307 1307 precond = "(objectClass=pykotaJob)" … … 1315 1315 if billingcode is not None : 1316 1316 where.append("(pykotaBillingCode=%s)" % self.userCharsetToDatabase(billingcode)) 1317 if jobid is not None : 1318 where.append("(pykotaJobId=%s)" % jobid) # TODO : jobid is text, so self.userCharsetToDatabase(jobid) but do all of them as well. 1317 1319 if where : 1318 1320 where = "(&%s)" % "".join([precond] + where) … … 1778 1780 return self.doModify(bcode.ident, fields) 1779 1781 1782 def refundJob(self, jobident) : 1783 """Marks a job as refunded in the history.""" 1784 dn = "cn=%s,%s" % (ident, self.info["jobbase"]) 1785 fields = { 1786 "pykotaAction" : "REFUND", 1787 } 1788 self.doModify(dn, fields) 1789 1780 1790 def storageUserFromRecord(self, username, record) : 1781 1791 """Returns a StorageUser instance from a database record.""" -
pykota/trunk/pykota/storages/sql.py
r2949 r3056 688 688 self.doModify("UPDATE billingcodes SET balance=balance + %s, pagecounter=pagecounter + %s WHERE id=%s" % (self.doQuote(balance), self.doQuote(pagecounter), self.doQuote(bcode.ident))) 689 689 690 def refundJob(self, jobident) : 691 """Marks a job as refunded in the history.""" 692 self.doModify("UPDATE jobhistory SET action='REFUND' WHERE id=%s;" % self.doQuote(jobident)) 693 690 694 def decreaseUserAccountBalance(self, user, amount) : 691 695 """Decreases user's account balance from an amount.""" … … 763 767 self.doModify("DELETE FROM printergroupsmembers WHERE groupid=%s AND printerid=%s" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident))) 764 768 765 def retrieveHistory(self, user=None, printer=None, hostname=None, billingcode=None, limit=100, start=None, end=None) :769 def retrieveHistory(self, user=None, printer=None, hostname=None, billingcode=None, jobid=None, limit=100, start=None, end=None) : 766 770 """Retrieves all print jobs for user on printer (or all) between start and end date, limited to first 100 results.""" 767 771 query = "SELECT jobhistory.*,username,printername FROM jobhistory,users,printers WHERE users.id=userid AND printers.id=printerid" … … 775 779 if billingcode is not None : 776 780 where.append("billingcode=%s" % self.doQuote(self.userCharsetToDatabase(billingcode))) 781 if jobid is not None : 782 where.append("jobid=%s" % self.doQuote(jobid)) # TODO : jobid is text, so self.userCharsetToDatabase(jobid) but do all of them as well. 777 783 if start is not None : 778 784 where.append("jobdate>=%s" % self.doQuote(start))