Changeset 1235

Show
Ignore:
Timestamp:
12/02/03 15:40:21 (21 years ago)
Author:
jalet
Message:

Some code refactoring.
New HTML reporter added, which is now used in the CGI script for web based
print quota reports. It will need some de-uglyfication though...

Location:
pykota/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/cgi-bin/printquota.cgi

    r1172 r1235  
    2323# 
    2424# $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# 
    2530# Revision 1.15  2003/10/24 22:06:42  jalet 
    2631# Initial support for browser's language preference added. 
     
    128133        print header % version.__version__ 
    129134        print self.body 
    130         print "<!-- %s -->" % str(getLanguagePreference()) 
    131135        print footer 
    132136         
     
    201205        self.body += self.htmlGroupsCheckbox(isgroup) 
    202206        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() 
    205210             
    206211if __name__ == "__main__" : 
  • pykota/trunk/NEWS

    r1227 r1235  
    2424    - 1.16alpah16 : 
    2525     
     26        - Code refactoring, and addition of a real HTML reporter, to  
     27          have nice looking and useful web based reports (in the future). 
     28         
    2629        - Added utolower configuration option to convert all usernames 
    2730          to lowercase during printing.  
  • pykota/trunk/pykota/reporter.py

    r1219 r1235  
    2222# 
    2323# $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# 
    2429# Revision 1.3  2003/11/25 23:46:40  jalet 
    2530# Don't try to verify if module name is valid, Python does this better than us. 
     
    5257        self.isgroup = isgroup 
    5358         
     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         
    54116def openReporter(tool, reporttype, printers, ugnames, isgroup) : 
    55117    """Returns a reporter instance of the proper reporter.""" 
  • pykota/trunk/pykota/reporters/text.py

    r1144 r1235  
    2222# 
    2323# $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# 
    2429# Revision 1.5  2003/10/07 09:07:29  jalet 
    2530# Character encoding added to please latest version of Python 
     
    4550     
    4651class Reporter(BaseReporter) :     
    47     """Base class for all PyKota command line tools.""" 
     52    """Text reporter.""" 
    4853    def generateReport(self) : 
    4954        """Produces a simple text report.""" 
    5055        self.report = [] 
    5156        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             
    5863            total = 0 
    5964            totalmoney = 0.0 
    6065            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)) 
    6369                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)) 
    6572                    total += pages 
    6673                    totalmoney += money 
    6774            else : 
    6875                # 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)) 
    7179                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)) 
    7382                    total += pages 
    7483                    totalmoney += money 
    7584            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)) 
    8288            self.report.append("")         
    8389        if self.isgroup :     
     
    8591        return "\n".join(self.report)     
    8692                         
    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