|
1
|
|
|
2
|
|
|
3
|
class ExtAttr(object):
|
|
4
|
"""classe pour l'accès à un attribut stocké dans une source de données externe
|
|
5
|
"""
|
|
6
|
|
|
7
|
def __init__(self, attr_name):
|
|
8
|
"""initialise le connecteur vers la source de données
|
|
9
|
attr_name est calculé automatiquement lors du chargement de ce module
|
|
10
|
"""
|
|
11
|
self.attr_name = attr_name
|
|
12
|
self.db_path = '/usr/share/sso/reverseTeleservice.db'
|
|
13
|
|
|
14
|
def get_local_attr(self, attr_values):
|
|
15
|
"""
|
|
16
|
retourne l'identifiant ENT d'un responsable ou élève en fonction
|
|
17
|
du vecteur de fédération FrEfuVecteur transmis par le guichet ATEN.
|
|
18
|
La correspondance est calculée en amont et stocké dans une base locale.
|
|
19
|
Renvoie également une liste des établissement communiqués dans le vecteur (il peut
|
|
20
|
être multivalué dans le cas d'un responsable).
|
|
21
|
"""
|
|
22
|
import shelve
|
|
23
|
from os.path import isfile
|
|
24
|
import unicodedata
|
|
25
|
|
|
26
|
def enleve_accents(val):
|
|
27
|
if type(val) == str:
|
|
28
|
print "** CONVERTED VAL TO UTF8 **"
|
|
29
|
val = unicode(val, 'UTF-8')
|
|
30
|
val = ''.join((c for c in unicodedata.normalize('NFD', val) if unicodedata.category(c) != 'Mn'))
|
|
31
|
return val.encode('UTF-8')
|
|
32
|
|
|
33
|
user_attrs = {}
|
|
34
|
if not isfile(self.db_path):
|
|
35
|
return values
|
|
36
|
|
|
37
|
if attr_values:
|
|
38
|
liste_rne = user_attrs.get('ENTEleveStructRattachId', [])
|
|
39
|
db = shelve.open(self.db_path, 'r')
|
|
40
|
|
|
41
|
for clerecherche in attr_values:
|
|
42
|
|
|
43
|
clerecherche = enleve_accents(clerecherche)
|
|
44
|
|
|
45
|
try:
|
|
46
|
typevect = clerecherche.split('|')[0]
|
|
47
|
cleidstruct = clerecherche.split('|')[3]
|
|
48
|
etabe = clerecherche.split('|')[4]
|
|
49
|
except:
|
|
50
|
print('Mauvais format de données pour la clé de fédération %s : %s' % (self.attr_name, clerecherche.encode('utf-8')))
|
|
51
|
|
|
52
|
continue
|
|
53
|
|
|
54
|
if etabe not in liste_rne:
|
|
55
|
liste_rne.append(etabe)
|
|
56
|
if typevect in ("1", "2") and clerecherche in db:
|
|
57
|
|
|
58
|
intid = db[clerecherche]
|
|
59
|
if user_attrs.get('intid', intid) != intid:
|
|
60
|
print "ATTENTION, ATTRIBUT INTID NON UNIQUE (%s : %s != %s)" % (clerecherche, user_attrs.get('intid', intid), intid)
|
|
61
|
user_attrs['intid'] = [intid]
|
|
62
|
elif typevect in ("3", "4"):
|
|
63
|
|
|
64
|
user_attrs['intid'] = cleidstruct
|
|
65
|
db.close()
|
|
66
|
user_attrs['ENTStructRattachId'] = liste_rne
|
|
67
|
return user_attrs
|