Show
Ignore:
Timestamp:
05/21/05 00:40:21 (19 years ago)
Author:
jerome
Message:

Now dumpykota and dumpykota.cgi accept start= and end=
to specify the starting and ending dates when dumping the
history.
Syntax allowed is :

start|end=YYYY[MM[DD[hh[mm[ss]]]]]

and this is REALLY powerful !

Location:
pykota/trunk/pykota/storages
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2222 r2266  
    10441044            self.doModify(pgroup.ident, fields)          
    10451045             
    1046     def retrieveHistory(self, user=None, printer=None, datelimit=None, hostname=None, billingcode=None, limit=100) : 
    1047         """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results.""" 
     1046    def retrieveHistory(self, user=None, printer=None, hostname=None, billingcode=None, limit=100, start=None, end=None) : 
     1047        """Retrieves all print jobs for user on printer (or all) between start and end date, limited to first 100 results.""" 
    10481048        precond = "(objectClass=pykotaJob)" 
    10491049        where = [] 
     
    11101110                minute = int(date[10:12]) 
    11111111                second = int(date[12:14]) 
    1112                 job.JobDate = "%04i-%02i-%02i %02i:%02i:%02i" % (year, month, day, hour, minute, second) 
    1113                 if (datelimit is None) or (job.JobDate <= datelimit) : 
     1112                job.JobDate = "%04i%02i%02i %02i:%02i:%02i" % (year, month, day, hour, minute, second) 
     1113                if ((start is None) and (end is None)) or \ 
     1114                   ((start is None) and (job.JobDate <= end)) or \ 
     1115                   ((end is None) and (job.JobDate >= start)) or \ 
     1116                   ((job.JobDate >= start) and (job.JobDate <= end)) : 
    11141117                    job.UserName = fields.get("pykotaUserName")[0] 
    11151118                    job.PrinterName = fields.get("pykotaPrinterName")[0] 
     
    13351338        else :     
    13361339            printer = None 
    1337         entries = self.retrieveHistory(user, printer, hostname=extractonly.get("hostname"), billingcode=extractonly.get("billingcode"), limit=None) 
     1340        startdate = extractonly.get("start") 
     1341        enddate = extractonly.get("end") 
     1342        for limit in ("start", "end") : 
     1343            try : 
     1344                del extractonly[limit] 
     1345            except KeyError :     
     1346                pass 
     1347        (startdate, enddate) = self.cleanDates(startdate, enddate) 
     1348        entries = self.retrieveHistory(user, printer, hostname=extractonly.get("hostname"), billingcode=extractonly.get("billingcode"), limit=None, start=startdate, end=enddate) 
    13381349        if entries : 
    13391350            result = [ ("username", "printername", "dn", "jobid", "pagecounter", "jobsize", "action", "jobdate", "filename", "title", "copies", "options", "jobprice", "hostname", "jobsizebytes", "md5sum", "pages", "billingcode") ]  
  • pykota/trunk/pykota/storages/sql.py

    r2222 r2266  
    124124    def extractHistory(self, extractonly={}) : 
    125125        """Extracts all jobhistory records.""" 
     126        startdate = extractonly.get("start") 
     127        enddate = extractonly.get("end") 
     128        for limit in ("start", "end") : 
     129            try : 
     130                del extractonly[limit] 
     131            except KeyError :     
     132                pass 
    126133        thefilter = self.createFilter(extractonly) 
    127134        if thefilter : 
    128135            thefilter = "AND %s" % thefilter 
     136        (startdate, enddate) = self.cleanDates(startdate, enddate) 
     137        if startdate and enddate :  
     138            thefilter = "%s AND jobdate>=%s AND jobdate<=%s" % (thefilter, self.doQuote(startdate), self.doQuote(enddate)) 
    129139        result = self.doRawSearch("SELECT users.username,printers.printername,jobhistory.* FROM users,printers,jobhistory WHERE users.id=jobhistory.userid AND printers.id=jobhistory.printerid %s ORDER BY jobhistory.id ASC" % thefilter) 
    130140        return self.prepareRawResult(result) 
    131          
     141             
    132142    def getAllUsersNames(self) :     
    133143        """Extracts all user names.""" 
     
    498508        self.doModify("DELETE FROM printergroupsmembers WHERE groupid=%s AND printerid=%s" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident))) 
    499509         
    500     def retrieveHistory(self, user=None, printer=None, datelimit=None, hostname=None, billingcode=None, limit=100) : 
    501         """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results.""" 
     510    def retrieveHistory(self, user=None, printer=None, hostname=None, billingcode=None, limit=100, start=None, end=None) : 
     511        """Retrieves all print jobs for user on printer (or all) between start and end date, limited to first 100 results.""" 
    502512        query = "SELECT jobhistory.*,username,printername FROM jobhistory,users,printers WHERE users.id=userid AND printers.id=printerid" 
    503513        where = [] 
     
    510520        if billingcode is not None :     
    511521            where.append("billingcode=%s" % self.doQuote(self.userCharsetToDatabase(billingcode))) 
    512         if datelimit is not None :     
    513             where.append("jobdate<=%s" % self.doQuote(datelimit)) 
     522        if start is not None :     
     523            where.append("jobdate>=%s" % self.doQuote(start)) 
     524        if end is not None :     
     525            where.append("jobdate<=%s" % self.doQuote(end)) 
    514526        if where :     
    515527            query += " AND %s" % " AND ".join(where)