Changeset 929

Show
Ignore:
Timestamp:
04/17/03 11:26:21 (21 years ago)
Author:
jalet
Message:

repykota now reports account balances too.

Location:
pykota/trunk
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/repykota

    r927 r929  
    2323# 
    2424# $Log$ 
     25# Revision 1.27  2003/04/17 09:26:21  jalet 
     26# repykota now reports account balances too. 
     27# 
    2528# Revision 1.26  2003/04/16 12:35:49  jalet 
    2629# Groups quota work now ! 
     
    177180            print _("Pages grace time: %idays") % self.config.getGraceDelay(printer) 
    178181            total = 0 
     182            totalmoney = 0.0 
    179183            if options["groups"] : 
    180                 print _("Group            used     soft     hard   grace        total") 
    181                 print "------------------------------------------------------------" 
     184                print _("Group           used    soft    hard    balance grace         total       paid")  
     185                print "------------------------------------------------------------------------------" 
    182186                for (ident, name) in self.storage.getPrinterGroups(printerid) : 
    183187                    quota = self.storage.getGroupPQuota(ident, printerid)  
    184                     total += self.printQuota(name, quota) 
     188                    balance = self.storage.getGroupBalance(ident) 
     189                    limitby = self.storage.getGroupLimitBy(ident) 
     190                    (pages, money) = self.printQuota(name, quota, balance, limitby) 
     191                    total += pages 
     192                    totalmoney += money 
    185193            else : 
    186194                # default is user quota report 
    187                 print _("User             used     soft     hard   grace        total") 
    188                 print "------------------------------------------------------------" 
     195                print _("User            used    soft    hard    balance grace         total       paid")  
     196                print "------------------------------------------------------------------------------" 
    189197                for (ident, name) in self.storage.getPrinterUsers(printerid) : 
    190198                    quota = self.storage.getUserPQuota(ident, printerid) 
    191                     total += self.printQuota(name, quota) 
    192             if total :         
    193                 print (" " * 43) + (_("Total : %9i") % total) 
     199                    balance = self.storage.getUserBalance(ident) 
     200                    limitby = self.storage.getUserLimitBy(ident) 
     201                    (pages, money) = self.printQuota(name, quota, balance, limitby) 
     202                    total += pages 
     203                    totalmoney += money 
     204            if total or totalmoney :         
     205                print (" " * 50) + (_("Total : %9i") % total) + (" %-12.12s" % ("%7.2f" % totalmoney)[:12]) 
    194206            printerpagecounter = self.storage.getPrinterPageCounter(printerid) 
    195207            try : 
     
    197209            except TypeError :      
    198210                msg = _("unknown") 
    199             print (" " * 44) + (_("Real : %s") % msg) 
     211            print (" " * 51) + (_("Real : %s") % msg) 
    200212            print         
     213        if options["groups"] :     
     214            print _("Totals may be inaccurate if some users are members of several groups.") 
    201215                         
    202     def printQuota(self, name, quota) : 
     216    def printQuota(self, name, quota, balance, limitby) : 
    203217        """Prints the quota information.""" 
    204218        if quota is not None : 
     
    208222            hardlimit = quota["hardlimit"] 
    209223            datelimit = quota["datelimit"] 
     224            if balance is not None : 
     225                (balance, lifetimepaid) = balance 
     226            else :     
     227                (balance, lifetimepaid) = 0.0 
    210228            if datelimit is not None : 
    211229                now = DateTime.now() 
     
    215233            else :     
    216234                datelimit = "" 
    217             reached = ((softlimit is not None) and (pagecounter >= softlimit) and "+") or "-" 
    218             print "%-10.10s %c %8i %8s %8s %10s %9i" % (name, reached, pagecounter, str(softlimit), str(hardlimit), str(datelimit)[:10], lifepagecounter) 
    219             return lifepagecounter 
     235            if limitby == "balance" :     
     236                reached = (((balance <= 0) and "+") or "-") + "B" 
     237            else : 
     238                reached = (((softlimit is not None) and (pagecounter >= softlimit) and "+") or "-") + "Q" 
     239            strbalance = ("%5.2f" % balance)[:10] 
     240            strlifetimepaid = ("%6.2f" % lifetimepaid)[:11] 
     241            print "%-9.9s %s %7i %7s %7s %10s %-10.10s %8i %-11.11s" % (name, reached, pagecounter, str(softlimit), str(hardlimit), strbalance, str(datelimit)[:10], lifepagecounter, strlifetimepaid) 
     242            return (lifepagecounter, lifetimepaid) 
    220243         
    221244                     
  • pykota/trunk/NEWS

    r927 r929  
    2222PyKota NEWS : 
    2323 
     24    - 1.03beta2 : 
     25     
     26        -  repykota now reports account balances too. 
     27         
    2428    - 1.03beta : 
    2529     
  • pykota/trunk/po/en/pykota.po

    r927 r929  
    2121# 
    2222# $Log$ 
     23# Revision 1.19  2003/04/17 09:26:21  jalet 
     24# repykota now reports account balances too. 
     25# 
    2326# Revision 1.18  2003/04/16 12:35:49  jalet 
    2427# Groups quota work now ! 
     
    145148msgstr "" 
    146149 
    147 msgid "Group            used     soft     hard   grace        total" 
     150msgid "Group           used    soft    hard    balance grace         total       paid" 
    148151msgstr "" 
    149152 
     
    160163msgstr "" 
    161164 
    162 msgid "User             used     soft     hard   grace        total" 
     165msgid "User            used    soft    hard    balance grace         total       paid" 
    163166msgstr "" 
    164167 
     
    304307"your group Print Quota is almost reached on printer %s." 
    305308msgstr "" 
     309 
     310msgid "Totals may be inaccurate if some users are members of several groups." 
     311msgstr "" 
  • pykota/trunk/po/fr/pykota.po

    r927 r929  
    2121# 
    2222# $Log$ 
     23# Revision 1.17  2003/04/17 09:26:21  jalet 
     24# repykota now reports account balances too. 
     25# 
    2326# Revision 1.16  2003/04/16 12:35:49  jalet 
    2427# Groups quota work now ! 
     
    146149msgstr "Valeur %s invalide pour la limite dure." 
    147150 
    148 msgid "Group            used     soft     hard   grace        total" 
    149 msgstr "Groupe           used     soft     hard   grace        total" 
    150  
     151msgid  "Group           used    soft    hard    balance grace         total       paid" 
     152msgstr "Groupe          util    soft    hard    solde   gr�         total       pay� 
    151153msgid "There's no printer matching %s" 
    152154msgstr "Aucune imprimante ne correspond �s" 
     
    161163msgstr "Nom de groupe %s invalide" 
    162164 
    163 msgid "User             used     soft     hard   grace        total" 
    164 msgstr "Utilisateur      used     soft     hard   grace        total" 
    165  
     165msgid  "User            used    soft    hard    balance grace         total       paid" 
     166msgstr "Utilisateur     util    soft    hard    solde   gr�         total       pay� 
    166167msgid "Invalid printer name %s" 
    167168msgstr "Nom d'imprimante %s invalide" 
     
    316317"Vous n'aurez bient�lus le droit d'imprimer car\n" 
    317318"le Quota d'Impression de votre groupe sur l'imprimante %s est presque atteint." 
     319 
     320msgid "Totals may be inaccurate if some users are members of several groups." 
     321msgstr "Les totaux peuvent �e faux si des utilisateurs sont dans plusieurs groupes." 
  • pykota/trunk/po/pykota.pot

    r927 r929  
    2121# 
    2222# $Log$ 
     23# Revision 1.19  2003/04/17 09:26:21  jalet 
     24# repykota now reports account balances too. 
     25# 
    2326# Revision 1.18  2003/04/16 12:35:49  jalet 
    2427# Groups quota work now ! 
     
    145148msgstr "" 
    146149 
    147 msgid "Group            used     soft     hard   grace        total" 
     150msgid "Group           used    soft    hard    balance grace         total       paid" 
    148151msgstr "" 
    149152 
     
    160163msgstr "" 
    161164 
    162 msgid "User             used     soft     hard   grace        total" 
     165msgid "User            used    soft    hard    balance grace         total       paid" 
    163166msgstr "" 
    164167 
     
    304307"your group Print Quota is almost reached on printer %s." 
    305308msgstr "" 
     309 
     310msgid "Totals may be inaccurate if some users are members of several groups." 
     311msgstr "" 
  • pykota/trunk/pykota/storages/sql.py

    r927 r929  
    2121# 
    2222# $Log$ 
     23# Revision 1.28  2003/04/17 09:26:21  jalet 
     24# repykota now reports account balances too. 
     25# 
    2326# Revision 1.27  2003/04/16 12:35:49  jalet 
    2427# Groups quota work now ! 
     
    254257    def getUserBalance(self, userid) :     
    255258        """Returns the current account balance for a given user.""" 
    256         result = self.doQuery("SELECT balance FROM users WHERE id=%s" % self.doQuote(userid)) 
    257         try : 
    258             return self.doParseResult(result)[0]["balance"] 
    259         except TypeError :      # Not found     
    260             return 
     259        result = self.doQuery("SELECT balance, lifetimepaid FROM users WHERE id=%s" % self.doQuote(userid)) 
     260        try : 
     261            result = self.doParseResult(result)[0] 
     262        except TypeError :      # Not found     
     263            return 
     264        else :     
     265            return (result["balance"], result["lifetimepaid"]) 
    261266         
    262267    def getGroupBalance(self, groupid) :     
    263268        """Returns the current account balance for a given group, as the sum of each of its users' account balance.""" 
    264         result = self.doQuery("SELECT SUM(balance) AS balance FROM users WHERE id in (SELECT userid FROM groupsmembers WHERE groupid=%s)" % self.doQuote(groupid)) 
    265         try : 
    266             return self.doParseResult(result)[0]["balance"] 
    267         except TypeError :      # Not found     
    268             return 
     269        result = self.doQuery("SELECT SUM(balance) AS balance, SUM(lifetimepaid) AS lifetimepaid FROM users WHERE id in (SELECT userid FROM groupsmembers WHERE groupid=%s)" % self.doQuote(groupid)) 
     270        try : 
     271            result = self.doParseResult(result)[0] 
     272        except TypeError :      # Not found     
     273            return 
     274        else :     
     275            return (result["balance"], result["lifetimepaid"]) 
    269276         
    270277    def getUserLimitBy(self, userid) :     
     
    286293    def setUserBalance(self, userid, balance) :     
    287294        """Sets the account balance for a given user to a fixed value.""" 
    288         current = self.getUserBalance(userid) 
     295        (current, lifetimepaid) = self.getUserBalance(userid) 
    289296        difference = balance - current 
    290297        self.increaseUserBalance(userid, difference) 
  • pykota/trunk/pykota/tool.py

    r927 r929  
    2121# 
    2222# $Log$ 
     23# Revision 1.34  2003/04/17 09:26:21  jalet 
     24# repykota now reports account balances too. 
     25# 
    2326# Revision 1.33  2003/04/16 12:35:49  jalet 
    2427# Groups quota work now ! 
     
    306309            else :     
    307310                # TODO : there's no warning (no account balance soft limit) 
     311                (balance, lifetimepaid) = balance 
    308312                if balance <= 0.0 : 
    309313                    action = "DENY" 
     
    381385            else :     
    382386                # TODO : there's no warning (no account balance soft limit) 
     387                (balance, lifetimepaid) = balance 
    383388                if balance <= 0.0 : 
    384389                    action = "DENY" 
  • pykota/trunk/pykota/version.py

    r927 r929  
    2121# 
    2222 
    23 __version__ = "1.03beta-unofficial" 
     23__version__ = "1.03beta2-unofficial" 
    2424 
    2525__doc__ = """PyKota : a complete Printing Quota Solution for CUPS."""