Index: /pykota/trunk/README
===================================================================
--- /pykota/trunk/README (revision 920)
+++ /pykota/trunk/README (revision 925)
@@ -68,4 +68,17 @@
         - Complete job history is saved. This will allow more
           complex reports in the future.
+          
+        - Price per page and price per job can be defined for  
+          every printers. A job's price is the sum of the
+          price per job for this printer plus the number of
+          pages multiplied by the price per page for this
+          printer.
+          
+        - User's account balance and lifetime paid money are now
+          stored in the Quota Storage, and account balance can be
+          used to limit the user printing instead of a print quota.
+          Actually you can limit either by account balance OR by
+          print quota, but maybe both should be checked at the 
+          same time. Tell me what you prefer.
           
 All the command line tools accept the -h | --help command line option
Index: /pykota/trunk/pykota/tool.py
===================================================================
--- /pykota/trunk/pykota/tool.py (revision 915)
+++ /pykota/trunk/pykota/tool.py (revision 925)
@@ -21,4 +21,9 @@
 #
 # $Log$
+# Revision 1.32  2003/04/16 08:53:14  jalet
+# Printing can now be limited either by user's account balance or by
+# page quota (the default). Quota report doesn't include account balance
+# yet, though.
+#
 # Revision 1.31  2003/04/15 11:30:57  jalet
 # More work done on money print charging.
@@ -286,49 +291,66 @@
         printerid = self.storage.getPrinterId(printername)
         userid = self.storage.getUserId(username)
-        quota = self.storage.getUserPQuota(userid, printerid)
-        if quota is None :
-            # Unknown user or printer or combination
-            policy = self.config.getPrinterPolicy(printername)
-            if policy in [None, "ALLOW"] :
-                action = "POLICY_ALLOW"
+        limitby = self.storage.getUserLimitBy(userid)
+        if limitby == "balance" : 
+            balance = self.storage.getUserBalance(userid)
+            if balance is None :
+                policy = self.config.getPrinterPolicy(printername)
+                if policy in [None, "ALLOW"] :
+                    action = "POLICY_ALLOW"
+                else :    
+                    action = "POLICY_DENY"
+                self.logger.log_message(_("Unable to find user %s's account balance, applying default policy (%s) for printer %s") % (username, action, printername))
             else :    
-                action = "POLICY_DENY"
-            self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (username, printername, action))
-        else :    
-            pagecounter = quota["pagecounter"]
-            softlimit = quota["softlimit"]
-            hardlimit = quota["hardlimit"]
-            datelimit = quota["datelimit"]
-            if softlimit is not None :
-                if pagecounter < softlimit :
+                # TODO : there's no warning (no account balance soft limit)
+                if balance <= 0.0 :
+                    action = "DENY"
+                else :    
                     action = "ALLOW"
+        else :
+            quota = self.storage.getUserPQuota(userid, printerid)
+            if quota is None :
+                # Unknown user or printer or combination
+                policy = self.config.getPrinterPolicy(printername)
+                if policy in [None, "ALLOW"] :
+                    action = "POLICY_ALLOW"
                 else :    
-                    if hardlimit is None :
-                        # only a soft limit, this is equivalent to having only a hard limit
-                        action = "DENY"
+                    action = "POLICY_DENY"
+                self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (username, printername, action))
+            else :    
+                pagecounter = quota["pagecounter"]
+                softlimit = quota["softlimit"]
+                hardlimit = quota["hardlimit"]
+                datelimit = quota["datelimit"]
+                if softlimit is not None :
+                    if pagecounter < softlimit :
+                        action = "ALLOW"
                     else :    
-                        if softlimit <= pagecounter < hardlimit :    
-                            now = DateTime.now()
-                            if datelimit is not None :
-                                datelimit = DateTime.ISO.ParseDateTime(datelimit)
-                            else :
-                                datelimit = now + self.config.getGraceDelay(printername)
-                                self.storage.setUserDateLimit(userid, printerid, datelimit)
-                            if now < datelimit :
-                                action = "WARN"
-                            else :    
+                        if hardlimit is None :
+                            # only a soft limit, this is equivalent to having only a hard limit
+                            action = "DENY"
+                        else :    
+                            if softlimit <= pagecounter < hardlimit :    
+                                now = DateTime.now()
+                                if datelimit is not None :
+                                    datelimit = DateTime.ISO.ParseDateTime(datelimit)
+                                else :
+                                    datelimit = now + self.config.getGraceDelay(printername)
+                                    self.storage.setUserDateLimit(userid, printerid, datelimit)
+                                if now < datelimit :
+                                    action = "WARN"
+                                else :    
+                                    action = "DENY"
+                            else :         
                                 action = "DENY"
-                        else :         
+                else :        
+                    if hardlimit is not None :
+                        # no soft limit, only a hard one.
+                        if pagecounter < hardlimit :
+                            action = "ALLOW"
+                        else :      
                             action = "DENY"
-            else :        
-                if hardlimit is not None :
-                    # no soft limit, only a hard one.
-                    if pagecounter < hardlimit :
+                    else :
+                        # Both are unset, no quota, i.e. accounting only
                         action = "ALLOW"
-                    else :      
-                        action = "DENY"
-                else :
-                    # Both are unset, no quota, i.e. accounting only
-                    action = "ALLOW"
         return action
     
Index: /pykota/trunk/pykota/storages/sql.py
===================================================================
--- /pykota/trunk/pykota/storages/sql.py (revision 921)
+++ /pykota/trunk/pykota/storages/sql.py (revision 925)
@@ -21,4 +21,9 @@
 #
 # $Log$
+# Revision 1.26  2003/04/16 08:53:14  jalet
+# Printing can now be limited either by user's account balance or by
+# page quota (the default). Quota report doesn't include account balance
+# yet, though.
+#
 # Revision 1.25  2003/04/15 21:58:33  jalet
 # edpykota now accepts a --delete option.
@@ -234,4 +239,20 @@
             return
         
+    def getUserLimitBy(self, userid) :    
+        """Returns the way in which user printing is limited."""
+        result = self.doQuery("SELECT limitby FROM users WHERE id=%s" % self.doQuote(userid))
+        try :
+            return self.doParseResult(result)[0]["limitby"]
+        except TypeError :      # Not found    
+            return
+        
+    def getGroupLimitBy(self, groupid) :    
+        """Returns the way in which group printing is limited."""
+        result = self.doQuery("SELECT limitby FROM groups WHERE id=%s" % self.doQuote(groupid))
+        try :
+            return self.doParseResult(result)[0]["limitby"]
+        except TypeError :      # Not found    
+            return
+        
     def setUserBalance(self, userid, balance) :    
         """Sets the account balance for a given user to a fixed value."""
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 919)
+++ /pykota/trunk/NEWS (revision 925)
@@ -68,5 +68,5 @@
           See http://web.mit.edu/source/third/lprng/doc/LPRng-HOWTO-15.html
           For a more accurate accounting, never switch your HP printers
-          off.
+          off. This is untested, please report any problem.
           
         - A bug was fixed when edpykota --add was used with users who already
@@ -80,4 +80,7 @@
         - Support for AppleTalk printers was added, see sample configuration
           file for details.
+          
+        - Users and group printing can now be controlled (limited) either by  
+          print quota or by account balance.
         
     - 1.02 :
Index: /pykota/trunk/po/en/pykota.po
===================================================================
--- /pykota/trunk/po/en/pykota.po (revision 924)
+++ /pykota/trunk/po/en/pykota.po (revision 925)
@@ -21,4 +21,9 @@
 #
 # $Log$
+# Revision 1.17  2003/04/16 08:53:14  jalet
+# Printing can now be limited either by user's account balance or by
+# page quota (the default). Quota report doesn't include account balance
+# yet, though.
+#
 # Revision 1.16  2003/04/16 08:22:09  jalet
 # More strict error detection.
@@ -271,2 +276,5 @@
 msgid "Invalid limitby value %s"
 msgstr ""
+
+msgid "Unable to find user %s's account balance, applying default policy (%s) for printer %s"
+msgstr ""
Index: /pykota/trunk/po/fr/pykota.po
===================================================================
--- /pykota/trunk/po/fr/pykota.po (revision 924)
+++ /pykota/trunk/po/fr/pykota.po (revision 925)
@@ -21,4 +21,9 @@
 #
 # $Log$
+# Revision 1.15  2003/04/16 08:53:14  jalet
+# Printing can now be limited either by user's account balance or by
+# page quota (the default). Quota report doesn't include account balance
+# yet, though.
+#
 # Revision 1.14  2003/04/16 08:22:10  jalet
 # More strict error detection.
@@ -279,2 +284,5 @@
 msgid "Invalid limitby value %s"
 msgstr "Valeur de l'option limitby %s invalide"
+
+msgid "Unable to find user %s's account balance, applying default policy (%s) for printer %s"
+msgstr "Impossible de trouver le solde du compte de l'utilisateur %s, action par d�ut (%s) appliqu�sur l'imprimante %s"
Index: /pykota/trunk/po/pykota.pot
===================================================================
--- /pykota/trunk/po/pykota.pot (revision 924)
+++ /pykota/trunk/po/pykota.pot (revision 925)
@@ -21,4 +21,9 @@
 #
 # $Log$
+# Revision 1.17  2003/04/16 08:53:14  jalet
+# Printing can now be limited either by user's account balance or by
+# page quota (the default). Quota report doesn't include account balance
+# yet, though.
+#
 # Revision 1.16  2003/04/16 08:22:09  jalet
 # More strict error detection.
@@ -271,2 +276,5 @@
 msgid "Invalid limitby value %s"
 msgstr ""
+
+msgid "Unable to find user %s's account balance, applying default policy (%s) for printer %s"
+msgstr ""
