Index: pykota/trunk/pykota/storages/sql.py
===================================================================
--- pykota/trunk/pykota/storages/sql.py (revision 1332)
+++ pykota/trunk/pykota/storages/sql.py (revision 1358)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.37  2004/02/23 22:53:21  jalet
+# Don't retrieve data when it's not needed, to avoid database queries
+#
 # Revision 1.36  2004/02/04 13:24:41  jalet
 # pkprinters can now remove printers from printers groups.
@@ -92,5 +95,4 @@
             printer.PricePerJob = fields.get("priceperjob")
             printer.PricePerPage = fields.get("priceperpage")
-            printer.LastJob = self.getPrinterLastJob(printer)
             printer.Exists = 1
         return printer    
@@ -139,5 +141,5 @@
             lastjob.ident = fields.get("id")
             lastjob.JobId = fields.get("jobid")
-            lastjob.User = self.getUser(fields.get("username"))
+            lastjob.UserName = fields.get("username")
             lastjob.PrinterPageCounter = fields.get("pagecounter")
             lastjob.JobSize = fields.get("jobsize")
@@ -204,5 +206,4 @@
                     printer.PricePerJob = record.get("priceperjob")
                     printer.PricePerPage = record.get("priceperpage")
-                    printer.LastJob = self.getPrinterLastJob(printer)
                     printer.Exists = 1
                     printers.append(printer)
@@ -391,6 +392,6 @@
                 job.JobOptions = fields.get("options")
                 job.JobDate = fields.get("jobdate")
-                job.User = self.getUser(fields.get("username"))
-                job.Printer = self.getPrinter(fields.get("printername"))
+                job.UserName = fields.get("username")
+                job.PrinterName = fields.get("printername")
                 job.Exists = 1
                 jobs.append(job)
Index: pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- pykota/trunk/pykota/storages/ldapstorage.py (revision 1357)
+++ pykota/trunk/pykota/storages/ldapstorage.py (revision 1358)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.55  2004/02/23 22:53:21  jalet
+# Don't retrieve data when it's not needed, to avoid database queries
+#
 # Revision 1.54  2004/02/20 16:38:39  jalet
 # ldapcache directive marked as experimental
@@ -472,5 +475,4 @@
             printer.PricePerJob = float(fields.get("pykotaPricePerJob")[0] or 0.0)
             printer.PricePerPage = float(fields.get("pykotaPricePerPage")[0] or 0.0)
-            printer.LastJob = self.getPrinterLastJob(printer)
             printer.uniqueMember = fields.get("uniqueMember", [])
             printer.Exists = 1
@@ -557,5 +559,5 @@
                 lastjob.ident = result[0][0]
                 lastjob.JobId = fields.get("pykotaJobId")[0]
-                lastjob.User = self.getUser(fields.get("pykotaUserName")[0])
+                lastjob.UserName = fields.get("pykotaUserName")[0]
                 lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter")[0] or 0)
                 lastjob.JobSize = int(fields.get("pykotaJobSize", [0])[0])
@@ -636,5 +638,4 @@
                 printer.PricePerPage = float(fields.get("pykotaPricePerPage")[0] or 0.0)
                 printer.uniqueMember = fields.get("uniqueMember", [])
-                printer.LastJob = self.getPrinterLastJob(printer)
                 printer.Exists = 1
                 printers.append(printer)
@@ -993,6 +994,6 @@
                 job.JobDate = "%04i-%02i-%02i %02i:%02i:%02i" % (year, month, day, hour, minute, second)
                 if (datelimit is None) or (job.JobDate <= datelimit) :
-                    job.User = self.getUser(fields.get("pykotaUserName")[0])
-                    job.Printer = self.getPrinter(fields.get("pykotaPrinterName")[0])
+                    job.UserName = fields.get("pykotaUserName")[0]
+                    job.PrinterName = fields.get("pykotaPrinterName")[0]
                     job.Exists = 1
                     jobs.append(job)
Index: pykota/trunk/pykota/storage.py
===================================================================
--- pykota/trunk/pykota/storage.py (revision 1333)
+++ pykota/trunk/pykota/storage.py (revision 1358)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.42  2004/02/23 22:53:21  jalet
+# Don't retrieve data when it's not needed, to avoid database queries
+#
 # Revision 1.41  2004/02/04 17:12:33  jalet
 # Removing a printer from a printers group should work now.
@@ -257,6 +260,13 @@
         self.PricePerPage = None
         self.PricePerJob = None
-        self.LastJob = None
-        
+        
+    def __getattr__(self, name) :    
+        """Delays data retrieval until it's really needed."""
+        if name == "LastJob" : 
+            self.LastJob = self.parent.getPrinterLastJob(self)
+            return self.LastJob
+        else :
+            raise AttributeError, name
+            
     def addJobToHistory(self, jobid, user, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None) :
         """Adds a job to the printer's history."""
@@ -309,5 +319,12 @@
         self.HardLimit = None
         self.DateLimit = None
-        self.ParentPrintersUserPQuota = (user.Exists and printer.Exists and parent.getParentPrintersUserPQuota(self)) or []
+        
+    def __getattr__(self, name) :    
+        """Delays data retrieval until it's really needed."""
+        if name == "ParentPrintersUserPQuota" : 
+            self.ParentPrintersUserPQuota = (self.User.Exists and self.Printer.Exists and self.parent.getParentPrintersUserPQuota(self)) or []
+            return self.ParentPrintersUserPQuota
+        else :
+            raise AttributeError, name
         
     def setDateLimit(self, datelimit) :    
@@ -383,6 +400,6 @@
     def __init__(self, parent) :
         StorageObject.__init__(self, parent)
-        self.User = None
-        self.Printer = None
+        self.UserName = None
+        self.PrinterName = None
         self.JobId = None
         self.PrinterPageCounter = None
@@ -396,4 +413,15 @@
         self.JobOptions = None
         
+    def __getattr__(self, name) :    
+        """Delays data retrieval until it's really needed."""
+        if name == "User" : 
+            self.User = self.parent.getUser(self.UserName)
+            return self.User
+        elif name == "Printer" :    
+            self.Printer = self.parent.getPrinter(self.PrinterName)
+            return self.Printer
+        else :
+            raise AttributeError, name
+        
 class StorageLastJob(StorageJob) :
     """Printer's Last Job class."""
@@ -401,4 +429,13 @@
         StorageJob.__init__(self, parent)
         self.Printer = printer
+        self.UserName = None
+        
+    def __getattr__(self, name) :    
+        """Delays data retrieval until it's really needed."""
+        if name == "User" : 
+            self.User = self.parent.getUser(self.UserName)
+            return self.User
+        else :    
+            raise AttributeError, name
         
     def setSize(self, jobsize) :
Index: pykota/trunk/pykota/version.py
===================================================================
--- pykota/trunk/pykota/version.py (revision 1356)
+++ pykota/trunk/pykota/version.py (revision 1358)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.18alpha7_unofficial"
+__version__ = "1.18alpha8_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: pykota/trunk/NEWS
===================================================================
--- pykota/trunk/NEWS (revision 1356)
+++ pykota/trunk/NEWS (revision 1358)
@@ -22,4 +22,9 @@
 PyKota NEWS :
 
+    - 1.18alpha8 :
+    
+        - Don't retrieve data when not needed.
+          This avoids many database queries.
+        
     - 1.18alpha7 :
     
