Show
Ignore:
Timestamp:
12/02/03 15:40:21 (20 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...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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."""