0001-toulouse-maelis-simplify-get_referential-71858.patch
passerelle/contrib/toulouse_maelis/models.py | ||
---|---|---|
87 | 87 |
] |
88 | 88 |
return {'list': response, 'dict': {x['id']: x['text'] for x in response}} |
89 | 89 | |
90 | 90 |
# remote referentials |
91 | 91 |
cache_key = 'maelis-%s-%s' % (self.pk, referential_name) |
92 | 92 |
data = cache.get(cache_key) |
93 | 93 |
if data is None: |
94 | 94 |
response = self.call('Family', 'read' + referential_name + 'List') |
95 |
data_list = [] |
|
95 | 96 |
if referential_name == 'Organ': |
96 |
data = { |
|
97 |
'list': [{'id': x.id, 'text': x.code} for x in response], |
|
98 |
'dict': {x.id: x.code for x in response}, |
|
99 |
} |
|
97 |
data_list = [{'id': x.id, 'text': x.code} for x in response] |
|
100 | 98 |
else: |
101 |
data = { |
|
102 |
'list': [{'id': x.code, 'text': x.libelle} for x in response], |
|
103 |
'dict': {x.code: x.libelle for x in response}, |
|
104 |
} |
|
99 |
data_list = [{'id': x.code, 'text': x.libelle} for x in response] |
|
100 |
data = { |
|
101 |
'list': data_list, |
|
102 |
'dict': {x['id']: x['text'] for x in data_list}, |
|
103 |
} |
|
105 | 104 |
# put in cache for two hours |
106 | 105 |
cache.set(cache_key, data, 3600 * 2) |
107 | 106 |
return data |
108 | 107 | |
109 | 108 |
def get_referential_value(self, referential_name, key): |
110 | 109 |
try: |
111 | 110 |
return self.get_referential(referential_name)['dict'][key] |
112 | 111 |
except KeyError: |
113 |
- |