Show
Ignore:
Timestamp:
01/12/04 15:35:02 (20 years ago)
Author:
jalet
Message:

Printing history added to CGI script.

Files:
1 modified

Legend:

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

    r1269 r1274  
    2222# 
    2323# $Log$ 
     24# Revision 1.48  2004/01/12 14:35:02  jalet 
     25# Printing history added to CGI script. 
     26# 
    2427# Revision 1.47  2004/01/10 09:44:02  jalet 
    2528# Fixed potential accuracy problem if a user printed on several printers at 
     
    192195import md5 
    193196 
    194 from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageLastJob,StorageUserPQuota,StorageGroupPQuota 
     197from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageJob,StorageLastJob,StorageUserPQuota,StorageGroupPQuota 
    195198 
    196199try : 
     
    861864                     }   
    862865            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 
    863911         
    864912    def deleteUser(self, user) :