Changeset 1235
- Timestamp:
- 12/02/03 15:40:21 (21 years ago)
- Location:
- pykota/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/cgi-bin/printquota.cgi
r1172 r1235 23 23 # 24 24 # $Log$ 25 # Revision 1.16 2003/12/02 14:40:20 jalet 26 # Some code refactoring. 27 # New HTML reporter added, which is now used in the CGI script for web based 28 # print quota reports. It will need some de-uglyfication though... 29 # 25 30 # Revision 1.15 2003/10/24 22:06:42 jalet 26 31 # Initial support for browser's language preference added. … … 128 133 print header % version.__version__ 129 134 print self.body 130 print "<!-- %s -->" % str(getLanguagePreference())131 135 print footer 132 136 … … 201 205 self.body += self.htmlGroupsCheckbox(isgroup) 202 206 if printers and ugmask : 203 self.reportingtool = openReporter(admin, "text", printers, ugmask.split(), isgroup) 204 self.body += "<pre>%s</pre>" % self.reportingtool.generateReport() 207 self.reportingtool = openReporter(admin, "html", printers, ugmask.split(), isgroup) 208 # self.body += "<pre>%s</pre>" % self.reportingtool.generateReport() 209 self.body += "%s" % self.reportingtool.generateReport() 205 210 206 211 if __name__ == "__main__" : -
pykota/trunk/NEWS
r1227 r1235 24 24 - 1.16alpah16 : 25 25 26 - Code refactoring, and addition of a real HTML reporter, to 27 have nice looking and useful web based reports (in the future). 28 26 29 - Added utolower configuration option to convert all usernames 27 30 to lowercase during printing. -
pykota/trunk/pykota/reporter.py
r1219 r1235 22 22 # 23 23 # $Log$ 24 # Revision 1.4 2003/12/02 14:40:21 jalet 25 # Some code refactoring. 26 # New HTML reporter added, which is now used in the CGI script for web based 27 # print quota reports. It will need some de-uglyfication though... 28 # 24 29 # Revision 1.3 2003/11/25 23:46:40 jalet 25 30 # Don't try to verify if module name is valid, Python does this better than us. … … 52 57 self.isgroup = isgroup 53 58 59 def getPrinterTitle(self, printer) : 60 return _("*** Report for %s quota on printer %s") % ((self.isgroup and "group") or "user", printer.Name) 61 62 def getPrinterGraceDelay(self, printer) : 63 return _("Pages grace time: %i days") % self.tool.config.getGraceDelay(printer.Name) 64 65 def getPrinterPrices(self, printer) : 66 return (_("Price per job: %.3f") % (printer.PricePerJob or 0.0), _("Price per page: %.3f") % (printer.PricePerPage or 0.0)) 67 68 def getReportHeader(self) : 69 if self.isgroup : 70 return _("Group used soft hard balance grace total paid") 71 else : 72 return _("User used soft hard balance grace total paid") 73 74 def getPrinterRealPageCounter(self, printer) : 75 try : 76 msg = "%9i" % printer.LastJob.PrinterPageCounter 77 except TypeError : 78 msg = _("unknown") 79 return _("Real : %s") % msg 80 81 def getTotals(self, total, totalmoney) : 82 return (_("Total : %9i") % (total or 0.0), ("%11s" % ("%7.2f" % (totalmoney or 0.0))[:11])) 83 84 def getQuota(self, entry, quota) : 85 """Prints the quota information.""" 86 lifepagecounter = int(quota.LifePageCounter or 0) 87 pagecounter = int(quota.PageCounter or 0) 88 balance = float(entry.AccountBalance or 0.0) 89 lifetimepaid = float(entry.LifeTimePaid or 0.0) 90 91 if entry.LimitBy and (entry.LimitBy.lower() == "balance") : 92 if balance <= 0 : 93 datelimit = "DENY" 94 reached = "+B" 95 else : 96 datelimit = "" 97 reached = "-B" 98 else : 99 if quota.DateLimit is not None : 100 now = DateTime.now() 101 datelimit = DateTime.ISO.ParseDateTime(quota.DateLimit) 102 if now >= datelimit : 103 datelimit = "DENY" 104 elif (quota.HardLimit is not None) and (pagecounter >= quota.HardLimit) : 105 datelimit = "DENY" 106 elif (quota.HardLimit is None) and (quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) : 107 datelimit = "DENY" 108 else : 109 datelimit = "" 110 reached = (((quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) and "+") or "-") + "Q" 111 112 strbalance = ("%5.2f" % balance)[:10] 113 strlifetimepaid = ("%6.2f" % lifetimepaid)[:10] 114 return (lifepagecounter, lifetimepaid, entry.Name, reached, pagecounter, str(quota.SoftLimit), str(quota.HardLimit), strbalance, str(datelimit)[:10], lifepagecounter, strlifetimepaid) 115 54 116 def openReporter(tool, reporttype, printers, ugnames, isgroup) : 55 117 """Returns a reporter instance of the proper reporter.""" -
pykota/trunk/pykota/reporters/text.py
r1144 r1235 22 22 # 23 23 # $Log$ 24 # Revision 1.6 2003/12/02 14:40:21 jalet 25 # Some code refactoring. 26 # New HTML reporter added, which is now used in the CGI script for web based 27 # print quota reports. It will need some de-uglyfication though... 28 # 24 29 # Revision 1.5 2003/10/07 09:07:29 jalet 25 30 # Character encoding added to please latest version of Python … … 45 50 46 51 class Reporter(BaseReporter) : 47 """ Base class for all PyKota command line tools."""52 """Text reporter.""" 48 53 def generateReport(self) : 49 54 """Produces a simple text report.""" 50 55 self.report = [] 51 56 for printer in self.printers : 52 self.report.append( _("*** Report for %s quota on printer %s") % ((self.isgroup and "group") or "user", printer.Name))53 self.report.append( _("Pages grace time: %i days") % self.tool.config.getGraceDelay(printer.Name))54 if printer.PricePerJob is not None :55 self.report.append(_("Price per job: %.3f") % printer.PricePerJob)56 if printer.PricePerPage is not None :57 self.report.append(_("Price per page: %.3f") % printer.PricePerPage)57 self.report.append(self.getPrinterTitle(printer)) 58 self.report.append(self.getPrinterGraceDelay(printer)) 59 (pjob, ppage) = self.getPrinterPrices(printer) 60 self.report.append(pjob) 61 self.report.append(ppage) 62 58 63 total = 0 59 64 totalmoney = 0.0 60 65 if self.isgroup : 61 self.report.append(_("Group used soft hard balance grace total paid")) 62 self.report.append("------------------------------------------------------------------------------") 66 header = self.getReportHeader() 67 self.report.append(header) 68 self.report.append('-' * len(header)) 63 69 for (group, grouppquota) in self.tool.storage.getPrinterGroupsAndQuotas(printer, self.ugnames) : 64 (pages, money) = self.printQuota(group, grouppquota) 70 (pages, money, name, reached, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid) = self.getQuota(group, grouppquota) 71 self.report.append("%-9.9s %s %7i %7s %7s %10s %-10.10s %8i %10s" % (name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid)) 65 72 total += pages 66 73 totalmoney += money 67 74 else : 68 75 # default is user quota report 69 self.report.append(_("User used soft hard balance grace total paid")) 70 self.report.append("------------------------------------------------------------------------------") 76 header = self.getReportHeader() 77 self.report.append(header) 78 self.report.append('-' * len(header)) 71 79 for (user, userpquota) in self.tool.storage.getPrinterUsersAndQuotas(printer, self.ugnames) : 72 (pages, money) = self.printQuota(user, userpquota) 80 (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid) = self.getQuota(user, userpquota) 81 self.report.append("%-9.9s %s %7i %7s %7s %10s %-10.10s %8i %10s" % (name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid)) 73 82 total += pages 74 83 totalmoney += money 75 84 if total or totalmoney : 76 self.report.append((" " * 50) + (_("Total : %9i") % total) + ("%11s" % ("%7.2f" % totalmoney)[:11])) 77 try : 78 msg = "%9i" % printer.LastJob.PrinterPageCounter 79 except TypeError : 80 msg = _("unknown") 81 self.report.append((" " * 51) + (_("Real : %s") % msg)) 85 (tpage, tmoney) = self.getTotals(total, totalmoney) 86 self.report.append((" " * 50) + tpage + tmoney) 87 self.report.append((" " * 51) + self.getPrinterRealPageCounter(printer)) 82 88 self.report.append("") 83 89 if self.isgroup : … … 85 91 return "\n".join(self.report) 86 92 87 def printQuota(self, entry, quota) :88 """Prints the quota information."""89 lifepagecounter = int(quota.LifePageCounter or 0)90 pagecounter = int(quota.PageCounter or 0)91 balance = float(entry.AccountBalance or 0.0)92 lifetimepaid = float(entry.LifeTimePaid or 0.0)93 94 if entry.LimitBy and (entry.LimitBy.lower() == "balance") :95 if balance <= 0 :96 datelimit = "DENY"97 reached = "+B"98 else :99 datelimit = ""100 reached = "-B"101 else :102 if quota.DateLimit is not None :103 now = DateTime.now()104 datelimit = DateTime.ISO.ParseDateTime(quota.DateLimit)105 if now >= datelimit :106 datelimit = "DENY"107 elif (quota.HardLimit is not None) and (pagecounter >= quota.HardLimit) :108 datelimit = "DENY"109 elif (quota.HardLimit is None) and (quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) :110 datelimit = "DENY"111 else :112 datelimit = ""113 reached = (((quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) and "+") or "-") + "Q"114 115 strbalance = ("%5.2f" % balance)[:10]116 strlifetimepaid = ("%6.2f" % lifetimepaid)[:10]117 self.report.append("%-9.9s %s %7i %7s %7s %10s %-10.10s %8i %10s" % (entry.Name, reached, pagecounter, str(quota.SoftLimit), str(quota.HardLimit), strbalance, str(datelimit)[:10], lifepagecounter, strlifetimepaid))118 return (lifepagecounter, lifetimepaid)119