98 |
98 |
'list': [{'id': x.id, 'text': x.code} for x in response],
|
99 |
99 |
'dict': {x.id: x.code for x in response},
|
100 |
100 |
}
|
101 |
101 |
else:
|
102 |
102 |
data = {
|
103 |
103 |
'list': [{'id': x.code, 'text': x.libelle} for x in response],
|
104 |
104 |
'dict': {x.code: x.libelle for x in response},
|
105 |
105 |
}
|
|
106 |
|
|
107 |
# remove redundant codes
|
|
108 |
uniq_text = set()
|
|
109 |
uniq_data = []
|
|
110 |
for item in data['list']:
|
|
111 |
item['text'] = item['text'].strip()
|
|
112 |
if item['text'] not in uniq_text:
|
|
113 |
uniq_data.append(item)
|
|
114 |
uniq_text.add(item['text'])
|
|
115 |
data['list'] = uniq_data
|
|
116 |
|
106 |
117 |
data['search'] = {to_ascii(x['text']).lower(): x for x in data['list']}
|
107 |
118 |
data['list'].sort(key=lambda c: c['text'])
|
108 |
119 |
|
109 |
120 |
# put in cache for two hours
|
110 |
121 |
cache.set(cache_key, data, 3600 * 2)
|
111 |
122 |
return data
|
112 |
123 |
|
113 |
124 |
def get_referential_value(self, referential_name, key, log_warning=False):
|
... | ... | |
423 |
434 |
@endpoint(
|
424 |
435 |
display_category='Famille',
|
425 |
436 |
description='liste des catégories socio-professionnelles',
|
426 |
437 |
name='read-csp-list',
|
427 |
438 |
perm='can_access',
|
428 |
439 |
parameters={
|
429 |
440 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
430 |
441 |
'q': {'description': 'Recherche en texte intégral'},
|
|
442 |
'limit': {'description': 'Nombre maximal d’éléments retournés'},
|
431 |
443 |
},
|
432 |
444 |
)
|
433 |
445 |
def read_csp_list(self, request, id=None, q=None):
|
434 |
|
data = self.get_referential_list('CSP', id, q)
|
435 |
|
|
436 |
|
# remove redundant codes
|
437 |
|
uniq_text = set()
|
438 |
|
uniq_data = []
|
439 |
|
for item in data:
|
440 |
|
item['text'] = item['text'].strip()
|
441 |
|
if item['text'] not in uniq_text:
|
442 |
|
uniq_data.append(item)
|
443 |
|
uniq_text.add(item['text'])
|
444 |
|
return {'data': uniq_data}
|
|
446 |
return {'data': self.get_referential_list('CSP', id, q)}
|
445 |
447 |
|
446 |
448 |
@endpoint(
|
447 |
449 |
display_category='Famille',
|
448 |
450 |
description='Liste des régimes alimentaires',
|
449 |
451 |
name='read-dietcode-list',
|
450 |
452 |
perm='can_access',
|
451 |
453 |
parameters={
|
452 |
454 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
453 |
|
-
|