Passage à lc_ldap et modernisation

This commit is contained in:
Gabriel Detraz 2015-08-23 20:05:03 +02:00
parent 8c503584f9
commit 13d8829e0d

View file

@ -1,4 +1,4 @@
#!/usr/bin/python #!/bin/bash /usr/scripts/python.sh
# -*- mode: python; coding: utf-8 -*- # -*- mode: python; coding: utf-8 -*-
# #
# total_impression.py # total_impression.py
@ -6,6 +6,7 @@
# #
# Copyright (C) 2007 Michel Blockelet <blockelet@crans.org> # Copyright (C) 2007 Michel Blockelet <blockelet@crans.org>
# #
# Revu et corrigé en 2015 par Gabriel Détraz
# This file is free software; you can redistribute it and/or modify # This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
@ -32,14 +33,11 @@ Options :
Les dates doivent etre de la forme jj/mm/aaaa.""" Les dates doivent etre de la forme jj/mm/aaaa."""
import sys import sys
sys.path.append("/usr/scripts/gestion/") from lc_ldap import shortcuts
from ldap_crans import crans_ldap from gestion.affich_tools import cprint
from config import ann_scol
from affich_tools import cprint
import time import time
db = crans_ldap() ldap = shortcuts.lc_ldap_admin()
date_debut_ann_scol = time.mktime((ann_scol, 8, 1, 0, 0, 0, 0, 0, 0))
def datestrtoint(strdate): def datestrtoint(strdate):
u""" Convertit une date en entier. """ u""" Convertit une date en entier. """
@ -52,7 +50,7 @@ def soldes_adherent(dlinf, dlsup, adherent, verbose):
totaldebit = 0 totaldebit = 0
totalcredit = 0 totalcredit = 0
for hist in adherent.historique(): for hist in adherent['historique']:
sep = ' ' sep = ' '
champ = hist.replace(',', '').replace(': ', '').split(sep) champ = hist.replace(',', '').replace(': ', '').split(sep)
if datestrtoint(champ[0]) >= dlinf and (dlsup == 0 or datestrtoint(champ[0]) <= dlsup): if datestrtoint(champ[0]) >= dlinf and (dlsup == 0 or datestrtoint(champ[0]) <= dlsup):
@ -112,19 +110,23 @@ def calcul_soldes():
totaldebit = 0 totaldebit = 0
totalcredit = 0 totalcredit = 0
liste = db.search("login=*")['adherent'] liste = ldap.search(u"uid=*",sizelimit=10000)
for adherent in liste: for adherent in liste:
try:
adhdebit, adhcredit = soldes_adherent(dlinf, dlsup, adherent, verbose) adhdebit, adhcredit = soldes_adherent(dlinf, dlsup, adherent, verbose)
if adhdebit + adhcredit > 0 and adhdebit + adhcredit < 1000000: # On evite Toto Passoir if adhdebit + adhcredit > 0 and adhdebit + adhcredit < 1000000: # On evite Toto Passoir
if verbose >= 2: if verbose >= 2:
cprint('-' * 40, 'cyan') cprint('-' * 40, 'cyan')
if verbose >= 1: if verbose >= 1:
cprint('Debit total pour ' + adherent.Nom() + ' : ' + str(adhdebit) + ' euros', 'rouge') name = unicode(adherent['prenom'][0]) + u" " + unicode(adherent['nom'][0])
cprint('Credit total pour ' + adherent.Nom() + ' : ' + str(adhcredit) + ' euros', 'vert') cprint(u'Debit total pour ' + name + u' : ' + unicode(adhdebit) + u' euros', 'rouge')
cprint(u'Credit total pour ' + name + u' : ' + unicode(adhcredit) + u' euros', 'vert')
cprint('=' * 40, 'bleu') cprint('=' * 40, 'bleu')
totaldebit += adhdebit totaldebit += adhdebit
totalcredit += adhcredit totalcredit += adhcredit
except KeyError:
pass
if verbose >= 1: if verbose >= 1:
cprint('=' * 80, 'bleu') cprint('=' * 80, 'bleu')
if dlinf == 0: if dlinf == 0: