Nettoie list_droits.py
* Fonctions plus bloc main * On n'utilise pas .rights(), car elle surcharge la liste des droits * Améliore un peu le code
This commit is contained in:
parent
f66fa61993
commit
21176bfcf9
1 changed files with 38 additions and 19 deletions
|
@ -1,32 +1,51 @@
|
||||||
#!/bin/bash /usr/scripts/python.sh
|
#!/bin/bash /usr/scripts/python.sh
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# list_droits.py --- Récupère la liste des adhérents ayant actuellement
|
||||||
|
# des droits.
|
||||||
|
"""Récupère la liste des adhérents avec des droits et l'affiche
|
||||||
|
triée par type de droit."""
|
||||||
|
|
||||||
from lc_ldap import shortcuts
|
from lc_ldap import shortcuts
|
||||||
|
from config.encoding import out_encoding
|
||||||
|
|
||||||
ldap = shortcuts.lc_ldap_readonly()
|
def fetch_adhs(ldap):
|
||||||
|
"""Récupère la liste des adhérents avec des droits et
|
||||||
|
les trie par droits actuellement possédés"""
|
||||||
|
adhs_avec_droits = ldap.search(u"droits=*")
|
||||||
|
|
||||||
txts = []
|
adhs_par_droit = {}
|
||||||
|
|
||||||
adhs = ldap.search(u"droits=*")
|
for adh in adhs_avec_droits:
|
||||||
droits={}
|
for droit in adh['droits']:
|
||||||
for adh in adhs:
|
adhs_par_droit.setdefault(droit, []).append(adh)
|
||||||
for droit in adh.rights():
|
|
||||||
droits[droit] = droits.get(droit, []) + [adh]
|
|
||||||
|
|
||||||
d=droits.keys()
|
return adhs_par_droit
|
||||||
d.sort()
|
|
||||||
|
|
||||||
for droit in d:
|
def make_output(adhs_par_droit):
|
||||||
adhs = droits[droit]
|
"""Génère une sortie à partir de la liste d'adhérents
|
||||||
|
triés par droits"""
|
||||||
|
d = adhs_par_droit.keys()
|
||||||
|
d.sort()
|
||||||
|
|
||||||
noms = []
|
output = []
|
||||||
|
|
||||||
txt = '%s\n' % droit
|
for droit in d:
|
||||||
for adh in adhs :
|
adhs = adhs_par_droit[droit]
|
||||||
noms.append(u'%s %s (%s)' % (adh['prenom'][0],adh['nom'][0],adh['historique'][0].split()[0].split('/',2)[-1]))
|
|
||||||
noms.sort()
|
|
||||||
txt += u' %s' % '\n '.join(noms)
|
|
||||||
|
|
||||||
txts.append(txt)
|
noms = []
|
||||||
|
|
||||||
print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(txts)
|
txt = '%s\n' % droit
|
||||||
|
for adh in adhs :
|
||||||
|
noms.append(u'%s %s' % (adh['prenom'][0], adh['nom'][0]))
|
||||||
|
noms.sort()
|
||||||
|
txt += u' %s' % '\n '.join(noms)
|
||||||
|
|
||||||
|
output.append(txt)
|
||||||
|
return output
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
LDAP = shortcuts.lc_ldap_readonly()
|
||||||
|
OUTPUT = make_output(fetch_adhs(LDAP))
|
||||||
|
|
||||||
|
print u'\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(OUTPUT).encode(out_encoding)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue