Changeset 1274
- Timestamp:
- 01/12/04 15:35:02 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/cgi-bin/printquota.cgi
r1262 r1274 23 23 # 24 24 # $Log$ 25 # Revision 1.23 2004/01/12 14:35:01 jalet 26 # Printing history added to CGI script. 27 # 25 28 # Revision 1.22 2004/01/09 07:58:53 jalet 26 29 # Changed URL to PyKota's logo … … 96 99 import os 97 100 import cgi 101 import urllib 98 102 99 103 from pykota import version … … 107 111 <head> 108 112 <title>PyKota Reports</title> 109 <link rel="stylesheet" type="text/css" href=" pykota.css" />113 <link rel="stylesheet" type="text/css" href="/pykota.css" /> 110 114 </head> 111 115 <body> … … 221 225 self.body += "<br />" 222 226 self.body += self.htmlGroupsCheckbox(isgroup) 223 if printers and ugmask : 224 self.reportingtool = openReporter(admin, "html", printers, ugmask.split(), isgroup) 225 # self.body += "<pre>%s</pre>" % self.reportingtool.generateReport() 226 self.body += "%s" % self.reportingtool.generateReport() 227 if not self.form.has_key("history") : 228 if printers and ugmask : 229 self.reportingtool = openReporter(admin, "html", printers, ugmask.split(), isgroup) 230 self.body += "%s" % self.reportingtool.generateReport() 231 else : 232 remuser = os.environ.get("REMOTE_USER", "root") 233 if remuser != "root" : 234 username = remuser 235 elif self.form.has_key("username") : 236 username = self.form["username"].value 237 else : 238 username = None 239 if username is not None : 240 user = self.storage.getUser(username) 241 else : 242 user =None 243 if self.form.has_key("printername") : 244 printer = self.storage.getPrinter(self.form["printername"].value) 245 else : 246 printer = None 247 if self.form.has_key("datelimit") : 248 datelimit = self.form["datelimit"].value 249 else : 250 datelimit = None 251 self.report = ["<h2>History</h2>"] 252 history = self.storage.retrieveHistory(user, printer, datelimit) 253 if not history : 254 self.report.append("<h3>Empty</h3>") 255 else : 256 self.report.append('<table class="pykotatable" border="1">') 257 headers = ["Date", "User", "Printer", "PageCounter", "JobId", "JobSize", "JobPrice", "Copies", "Title", "Filename", "Options", "Action"] 258 self.report.append('<tr class="pykotacolsheader">%s</tr>' % "".join(["<th>%s</th>" % h for h in headers])) 259 oddeven = 0 260 for job in history : 261 oddeven += 1 262 if oddeven % 2 : 263 oddevenclass = "odd" 264 else : 265 oddevenclass = "even" 266 if job.JobAction == "DENY" : 267 oddevenclass = "deny" 268 elif job.JobAction == "WARN" : 269 oddevenclass = "warn" 270 self.report.append('<tr class="%s">%s</tr>' % (oddevenclass, "".join(["<td>%s</td>" % h for h in (job.JobDate, job.User.Name, job.Printer.Name, job.PrinterPageCounter, job.JobId, job.JobSize, job.JobPrice, job.JobCopies, job.JobTitle, job.JobFileName, job.JobOptions, job.JobAction)]))) 271 self.report.append('</table>') 272 dico = { "history" : 1, 273 "datelimit" : job.JobDate, 274 } 275 if user and user.Exists : 276 dico.update({ "username" : user.Name }) 277 if printer and printer.Exists : 278 dico.update({ "printername" : printer.Name }) 279 prevurl = "%s?%s" % (os.environ.get("SCRIPT_NAME", ""), urllib.urlencode(dico)) 280 self.report.append('<a href="%s">Previous page</a>' % prevurl) 281 self.body = "\n".join(self.report) 227 282 228 283 if __name__ == "__main__" : -
pykota/trunk/NEWS
r1272 r1274 24 24 - 1.16alpha24 : 25 25 26 - CGI script now can show the printing history. 27 26 28 - Bug wrt number of copies should be fixed. 27 29 -
pykota/trunk/pykota/reporters/html.py
r1257 r1274 22 22 # 23 23 # $Log$ 24 # Revision 1.6 2004/01/12 14:35:01 jalet 25 # Printing history added to CGI script. 26 # 24 27 # Revision 1.5 2004/01/08 14:10:33 jalet 25 28 # Copyright year changed. … … 37 40 # 38 41 42 import os 39 43 from mx import DateTime 40 44 … … 75 79 else : 76 80 oddevenclass = "warn" 81 if not self.tool.config.getDisableHistory() : 82 name = '<a href="%s?username=%s&printername=%s&history=1">%s</a>' % (os.environ.get("SCRIPT_NAME", ""), name, printer.Name, name) 77 83 self.report.append('<tr class="%s">%s</tr>' % (oddevenclass, "".join(["<td>%s</td>" % h for h in (name, reached, pagecounter, soft, hard, balance, datelimit or " ", lifepagecounter, lifetimepaid)]))) 78 84 total += pages -
pykota/trunk/pykota/storage.py
r1269 r1274 22 22 # 23 23 # $Log$ 24 # Revision 1.37 2004/01/12 14:35:01 jalet 25 # Printing history added to CGI script. 26 # 24 27 # Revision 1.36 2004/01/10 09:44:02 jalet 25 28 # Fixed potential accuracy problem if a user printed on several printers at … … 338 341 self.HardLimit = hardlimit 339 342 340 class Storage LastJob(StorageObject) :343 class StorageJob(StorageObject) : 341 344 """Printer's Last Job class.""" 342 def __init__(self, parent , printer) :345 def __init__(self, parent) : 343 346 StorageObject.__init__(self, parent) 344 self.Printer = printer 347 self.User = None 348 self.Printer = None 345 349 self.JobId = None 346 self.User = None347 350 self.PrinterPageCounter = None 348 351 self.JobSize = None … … 355 358 self.JobOptions = None 356 359 360 class StorageLastJob(StorageJob) : 361 """Printer's Last Job class.""" 362 def __init__(self, parent, printer) : 363 StorageJob.__init__(self, parent) 364 self.Printer = printer 365 357 366 def setSize(self, jobsize) : 358 367 """Sets the last job's size.""" … … 361 370 self.JobSize = jobsize 362 371 self.JobPrice = jobprice 363 372 364 373 class BaseStorage : 365 374 def __init__(self, pykotatool) : -
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.""" -
pykota/trunk/stylesheets/README
r1263 r1274 21 21 22 22 This directory contains CSS stylesheets for use with PyKota's web based 23 tools. Just copy them in the same directory (e.g. /usr/lib/cgi-bin) 23 tools. Just copy them in your web server's DocumentRoot (e.g. /var/www) 24 so that the CGI scripts will find them. 24 25 25 26 ====================================================================