Révision 41211c39
Ajouté par Thomas Noël il y a plus de 9 ans
usr/local/univnautes/sp/sp/management/commands/update-geoinfos.py | ||
---|---|---|
42 | 42 |
|
43 | 43 |
def handle(self, *args, **options): |
44 | 44 |
idps = {} |
45 |
|
|
45 |
|
|
46 | 46 |
sp = pfconfigxml.get_sp() |
47 | 47 |
for url in sp.get('ui', {}).get('geolocations', []): |
48 | 48 |
try: |
... | ... | |
78 | 78 |
idps[entityid] = dots |
79 | 79 |
else: |
80 | 80 |
idps[entityid].update(dots) |
81 |
|
|
81 |
|
|
82 | 82 |
geoinfos = [] |
83 |
|
|
83 |
|
|
84 | 84 |
n = 0 |
85 | 85 |
for idp in LibertyProvider.objects.all(): |
86 | 86 |
if idp.entity_id in idps: |
87 | 87 |
geos = list(idps[idp.entity_id]) |
88 | 88 |
else: |
89 |
print 'idp %s do not have geo, randomize it' % idp.entity_id |
|
89 |
# print 'idp %s do not have geo, randomize it' % idp.entity_id
|
|
90 | 90 |
geos = [(47.0+2.0*math.sin(n), 2.5+3.0*math.cos(n))] |
91 | 91 |
n += 1 |
92 | 92 |
geoinfos.append({ |
... | ... | |
94 | 94 |
'entityid': idp.entity_id, |
95 | 95 |
'geo': geos |
96 | 96 |
}) |
97 |
|
|
97 |
|
|
98 | 98 |
tempfilename = '/var/tmp/univnautes-geoinfo.js-%s' % os.getpid() |
99 |
|
|
99 |
|
|
100 | 100 |
with open(tempfilename, 'wb') as f: |
101 | 101 |
f.write('geoinfos = ') |
102 | 102 |
json.dump(geoinfos, f, indent=2) |
103 | 103 |
f.write('\n') |
104 |
|
|
104 |
|
|
105 | 105 |
os.rename(tempfilename, GEOINFOS_JS) |
106 | 106 |
|
Formats disponibles : Unified diff
update-geoinfos.py: dont print when randomize geos