Index: /pykota/trunk/pykota/tool.py
===================================================================
--- /pykota/trunk/pykota/tool.py (revision 699)
+++ /pykota/trunk/pykota/tool.py (revision 708)
@@ -15,4 +15,7 @@
 #
 # $Log$
+# Revision 1.4  2003/02/05 23:26:22  jalet
+# Incorrect handling of grace delay
+#
 # Revision 1.3  2003/02/05 22:16:20  jalet
 # DEVICE_URI is undefined outside of CUPS, i.e. for normal command line tools
@@ -30,4 +33,6 @@
 import os
 import smtplib
+
+from mx import DateTime
 
 from pykota import config
@@ -73,4 +78,34 @@
         self.sendMessage(self.adminmail, "Subject: %s\n\n%s" % (subject, message))
         
+    def checkUserPQuota(self, username, printername) :
+        """Checks the user quota on a printer and deny or accept the job."""
+        now = DateTime.now()
+        quota = self.storage.getUserPQuota(username, printername)
+        pagecounter = quota["pagecounter"]
+        softlimit = quota["softlimit"]
+        hardlimit = quota["hardlimit"]
+        datelimit = quota["datelimit"]
+        if datelimit :
+            datelimit = DateTime.DateTime(datelimit)    # TODO : check this !
+        if softlimit is not None :
+            if pagecounter < softlimit :
+                action = "ALLOW"
+            elif hardlimit is not None :
+                 if softlimit <= pagecounter < hardlimit :    
+                     if datelimit is None :
+                         self.storage.doQuery("UPDATE userpquota SET datelimit=%s::DATETIME WHERE userid=%s AND printerid=%s;" % (self.doQuote("%04i-%02i-%02i %02i:%02i" % (now.year, now.month, now.day, now.hour, now.minute)), self.doQuote(self.getUserId(username)), self.doQuote(self.getPrinterId(printername))))
+                         datelimit = now
+                     if (now - datelimit) <= self.config.getGraceDelay() :
+                         action = "WARN"
+                     else :    
+                         action = "DENY"
+                 else :         
+                     action = "DENY"
+            else :        
+                action = "DENY"
+        else :        
+            action = "ALLOW"
+        return (action, (hardlimit - pagecounter), datelimit)
+    
     def warnQuotaPrinter(self, username) :
         """Checks a user quota and send him a message if quota is exceeded on current printer."""
Index: /pykota/trunk/pykota/storages/sql.py
===================================================================
--- /pykota/trunk/pykota/storages/sql.py (revision 706)
+++ /pykota/trunk/pykota/storages/sql.py (revision 708)
@@ -15,4 +15,7 @@
 #
 # $Log$
+# Revision 1.5  2003/02/05 23:26:22  jalet
+# Incorrect handling of grace delay
+#
 # Revision 1.4  2003/02/05 23:02:10  jalet
 # Typo
@@ -30,6 +33,4 @@
 #
 #
-
-from mx import DateTime
 
 class SQLStorage :    
@@ -86,34 +87,2 @@
         self.updateUserPQuota(username, printername, -pagebought)
         
-    def checkUserPQuota(self, username, printername) :
-        # TODO : this doesn't work as expected wrt dates
-        # TODO : GRACEDELAY should come from the configuration file
-        # TODO : move this into the PyKotaTool class
-        now = DateTime.now()
-        quota = self.getUserPQuota(username, printername)
-        pagecounter = quota["pagecounter"]
-        softlimit = quota["softlimit"]
-        hardlimit = quota["hardlimit"]
-        datelimit = quota["datelimit"]
-        if datelimit :
-            datelimit = DateTime.DateTime(datelimit)    # TODO : check this !
-        if softlimit is not None :
-            if pagecounter < softlimit :
-                action = "ALLOW"
-            elif hardlimit is not None :
-                 if softlimit <= pagecounter < hardlimit :    
-                     if datelimit is None :
-                         self.doQuery("UPDATE userpquota SET datelimit=%s::DATETIME WHERE userid=%s AND printerid=%s;" % (self.doQuote("%04i-%02i-%02i %02i:%02i" % (now.year, now.month, now.day, now.hour, now.minute)), self.doQuote(self.getUserId(username)), self.doQuote(self.getPrinterId(printername))))
-                         datelimit = now
-                     if (now - datelimit) <= GRACEDELAY :
-                         action = "WARN"
-                     else :    
-                         action = "DENY"
-                 else :         
-                     action = "DENY"
-            else :        
-                action = "DENY"
-        else :        
-            action = "ALLOW"
-        return (action, (hardlimit - pagecounter), datelimit)
-    
Index: /pykota/trunk/pykota/config.py
===================================================================
--- /pykota/trunk/pykota/config.py (revision 707)
+++ /pykota/trunk/pykota/config.py (revision 708)
@@ -15,4 +15,7 @@
 #
 # $Log$
+# Revision 1.3  2003/02/05 23:26:22  jalet
+# Incorrect handling of grace delay
+#
 # Revision 1.2  2003/02/05 23:09:20  jalet
 # Name conflict
@@ -129,2 +132,6 @@
         """Returns the full name of the Print Quota Administrator."""
         return self.config.get("global", "admin")
+        
+    def getGraceDelay(self) :    
+        """Returns the grace delay in days."""
+        return int(self.config.get("global", "gracedelay"))
