Changeset 1274 for pykota/trunk/pykota/storages
- Timestamp:
- 01/12/04 15:35:02 (20 years ago)
- Location:
- pykota/trunk/pykota/storages
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/ldapstorage.py
r1269 r1274 22 22 # 23 23 # $Log$ 24 # Revision 1.48 2004/01/12 14:35:02 jalet 25 # Printing history added to CGI script. 26 # 24 27 # Revision 1.47 2004/01/10 09:44:02 jalet 25 28 # Fixed potential accuracy problem if a user printed on several printers at … … 192 195 import md5 193 196 194 from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,Storage LastJob,StorageUserPQuota,StorageGroupPQuota197 from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageJob,StorageLastJob,StorageUserPQuota,StorageGroupPQuota 195 198 196 199 try : … … 861 864 } 862 865 self.doModify(pgroup.ident, fields) 866 867 def retrieveHistory(self, user=None, printer=None, datelimit=None, limit=100) : 868 """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results.""" 869 precond = "(objectClass=pykotaJob)" 870 where = [] 871 if (user is not None) and user.Exists : 872 where.append("(pykotaUserName=%s)" % user.Name) 873 if (printer is not None) and printer.Exists : 874 where.append("(pykotaPrinterName=%s)" % printer.Name) 875 if where : 876 where = "(&%s)" % "".join([precond] + where) 877 else : 878 where = precond 879 jobs = [] 880 result = self.doSearch(where, fields=["pykotaUserName", "pykotaPrinterName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaAction", "pykotaJobSize", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base=self.info["jobbase"]) 881 if result : 882 for (ident, fields) in result : 883 job = StorageJob(self) 884 job.ident = ident 885 job.JobId = fields.get("pykotaJobId")[0] 886 job.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter")[0] or 0) 887 job.JobSize = int(fields.get("pykotaJobSize", [0])[0]) 888 job.JobPrice = float(fields.get("pykotaJobPrice", [0.0])[0]) 889 job.JobAction = fields.get("pykotaAction")[0] 890 job.JobFileName = fields.get("pykotaFileName", [""])[0] 891 job.JobTitle = fields.get("pykotaTitle", [""])[0] 892 job.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 893 job.JobOptions = fields.get("pykotaOptions", [""])[0] 894 date = fields.get("createTimestamp")[0] 895 year = int(date[:4]) 896 month = int(date[4:6]) 897 day = int(date[6:8]) 898 hour = int(date[8:10]) 899 minute = int(date[10:12]) 900 second = int(date[12:14]) 901 job.JobDate = "%04i-%02i-%02i %02i:%02i:%02i" % (year, month, day, hour, minute, second) 902 if (datelimit is None) or (job.JobDate <= datelimit) : 903 job.User = self.getUser(fields.get("pykotaUserName")[0]) 904 job.Printer = self.getPrinter(fields.get("pykotaPrinterName")[0]) 905 job.Exists = 1 906 jobs.append(job) 907 jobs.sort(lambda x,y : cmp(y.JobDate, x.JobDate)) 908 if limit : 909 jobs = jobs[:int(limit)] 910 return jobs 863 911 864 912 def deleteUser(self, user) : -
pykota/trunk/pykota/storages/pgstorage.py
r1269 r1274 22 22 # 23 23 # $Log$ 24 # Revision 1.32 2004/01/12 14:35:02 jalet 25 # Printing history added to CGI script. 26 # 24 27 # Revision 1.31 2004/01/10 09:44:02 jalet 25 28 # Fixed potential accuracy problem if a user printed on several printers at … … 128 131 # 129 132 130 from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,Storage LastJob,StorageUserPQuota,StorageGroupPQuota133 from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageJob,StorageLastJob,StorageUserPQuota,StorageGroupPQuota 131 134 132 135 try : … … 533 536 self.doModify("INSERT INTO printergroupsmembers (groupid, printerid) VALUES (%s, %s)" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident))) 534 537 538 def retrieveHistory(self, user=None, printer=None, datelimit=None, limit=100) : 539 """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results.""" 540 query = "SELECT * FROM jobhistory" 541 where = [] 542 if (user is not None) and user.Exists : 543 where.append("userid=%s" % self.doQuote(user.ident)) 544 if (printer is not None) and printer.Exists : 545 where.append("printerid=%s" % self.doQuote(printer.ident)) 546 if datelimit is not None : 547 where.append("jobdate<=%s" % self.doQuote(datelimit)) 548 if where : 549 query += "WHERE %s" % " AND ".join(where) 550 query += " ORDER BY id DESC" 551 if limit : 552 query += " LIMIT %s" % self.doQuote(int(limit)) 553 jobs = [] 554 result = self.doSearch(query) 555 if result : 556 for fields in result : 557 job = StorageJob(self) 558 job.ident = fields.get("id") 559 job.JobId = fields.get("jobid") 560 job.PrinterPageCounter = fields.get("pagecounter") 561 job.JobSize = fields.get("jobsize") 562 job.JobPrice = fields.get("jobprice") 563 job.JobAction = fields.get("action") 564 job.JobFileName = fields.get("filename") 565 job.JobTitle = fields.get("title") 566 job.JobCopies = fields.get("copies") 567 job.JobOptions = fields.get("options") 568 job.JobDate = fields.get("jobdate") 569 job.User = self.getUser(fields.get("userid")) 570 job.Printer = self.getPrinter(fields.get("printerid")) 571 job.Exists = 1 572 jobs.append(job) 573 return jobs 574 535 575 def deleteUser(self, user) : 536 576 """Completely deletes an user from the Quota Storage."""