125 |
125 |
try:
|
126 |
126 |
return self.get_referential(referential_name)['dict'][key]
|
127 |
127 |
except KeyError:
|
128 |
128 |
if log_warning:
|
129 |
129 |
# Maelis DB not properly configurated
|
130 |
130 |
self.logger.warning("No '%s' key into Maelis '%s' referential", key, referential_name)
|
131 |
131 |
return None
|
132 |
132 |
|
133 |
|
def get_referential_list(self, referential_name, id=None, q=None):
|
|
133 |
def get_referential_list(self, referential_name, id=None, q=None, limit=None):
|
134 |
134 |
data = []
|
|
135 |
max_items = 0
|
|
136 |
|
|
137 |
# full referential is returned if id, q and limit are all not specified
|
|
138 |
if limit or (id is not None or q is not None):
|
|
139 |
try:
|
|
140 |
max_items = min(int(limit), 20)
|
|
141 |
except (TypeError, ValueError):
|
|
142 |
max_items = 10
|
135 |
143 |
|
136 |
144 |
if id:
|
137 |
145 |
text = self.get_referential_value(referential_name, id)
|
138 |
146 |
if text:
|
139 |
147 |
data.append({'id': id, 'text': text})
|
140 |
148 |
elif q is not None:
|
141 |
|
key = to_ascii(q.strip()).lower()
|
142 |
|
if key:
|
143 |
|
items = self.get_referential(referential_name)['search'].items()
|
144 |
|
data = [v for k, v in items if key in k]
|
|
149 |
search_key = to_ascii(q.strip()).lower()
|
|
150 |
if search_key:
|
|
151 |
nb_found = 0
|
|
152 |
for key, value in self.get_referential(referential_name)['search'].items():
|
|
153 |
if search_key in key:
|
|
154 |
data.append(value)
|
|
155 |
nb_found += 1
|
|
156 |
if nb_found >= max_items:
|
|
157 |
break
|
145 |
158 |
else:
|
146 |
159 |
data = self.get_referential(referential_name)['list']
|
|
160 |
|
|
161 |
if max_items:
|
|
162 |
return data[:max_items]
|
147 |
163 |
return data
|
148 |
164 |
|
149 |
165 |
def get_link(self, NameID):
|
150 |
166 |
try:
|
151 |
167 |
return self.link_set.get(name_id=NameID)
|
152 |
168 |
except Link.DoesNotExist:
|
153 |
169 |
raise APIError('User not linked to family', err_code='not-linked')
|
154 |
170 |
|
... | ... | |
395 |
411 |
@endpoint(
|
396 |
412 |
display_category='Famille',
|
397 |
413 |
description='Liste des catégories',
|
398 |
414 |
name='read-category-list',
|
399 |
415 |
perm='can_access',
|
400 |
416 |
parameters={
|
401 |
417 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
402 |
418 |
'q': {'description': 'Recherche en texte intégral'},
|
|
419 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
403 |
420 |
},
|
404 |
421 |
)
|
405 |
|
def read_category_list(self, request, id=None, q=None):
|
406 |
|
return {'data': self.get_referential_list('Category', id, q)}
|
|
422 |
def read_category_list(self, request, id=None, q=None, limit=None):
|
|
423 |
return {'data': self.get_referential_list('Category', id, q, limit)}
|
407 |
424 |
|
408 |
425 |
@endpoint(
|
409 |
426 |
display_category='Famille',
|
410 |
427 |
description='Liste des civilités',
|
411 |
428 |
name='read-civility-list',
|
412 |
429 |
perm='can_access',
|
413 |
430 |
parameters={
|
414 |
431 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
415 |
432 |
'q': {'description': 'Recherche en texte intégral'},
|
|
433 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
416 |
434 |
},
|
417 |
435 |
)
|
418 |
|
def read_civility_list(self, request, id=None, q=None):
|
419 |
|
return {'data': self.get_referential_list('Civility', id, q)}
|
|
436 |
def read_civility_list(self, request, id=None, q=None, limit=None):
|
|
437 |
return {'data': self.get_referential_list('Civility', id, q, limit)}
|
420 |
438 |
|
421 |
439 |
@endpoint(
|
422 |
440 |
display_category='Famille',
|
423 |
441 |
description='Liste des compléments du numéro de voie',
|
424 |
442 |
name='read-complement-list',
|
425 |
443 |
perm='can_access',
|
426 |
444 |
parameters={
|
427 |
445 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
428 |
446 |
'q': {'description': 'Recherche en texte intégral'},
|
|
447 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
429 |
448 |
},
|
430 |
449 |
)
|
431 |
|
def read_complement_list(self, request, id=None, q=None):
|
432 |
|
return {'data': self.get_referential_list('Complement', id, q)}
|
|
450 |
def read_complement_list(self, request, id=None, q=None, limit=None):
|
|
451 |
return {'data': self.get_referential_list('Complement', id, q, limit)}
|
433 |
452 |
|
434 |
453 |
@endpoint(
|
435 |
454 |
display_category='Famille',
|
436 |
455 |
description='liste des catégories socio-professionnelles',
|
437 |
456 |
name='read-csp-list',
|
438 |
457 |
perm='can_access',
|
439 |
458 |
parameters={
|
440 |
459 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
441 |
460 |
'q': {'description': 'Recherche en texte intégral'},
|
442 |
|
'limit': {'description': 'Nombre maximal d’éléments retournés'},
|
|
461 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
443 |
462 |
},
|
444 |
463 |
)
|
445 |
|
def read_csp_list(self, request, id=None, q=None):
|
446 |
|
return {'data': self.get_referential_list('CSP', id, q)}
|
|
464 |
def read_csp_list(self, request, id=None, q=None, limit=None):
|
|
465 |
return {'data': self.get_referential_list('CSP', id, q, limit)}
|
447 |
466 |
|
448 |
467 |
@endpoint(
|
449 |
468 |
display_category='Famille',
|
450 |
469 |
description='Liste des régimes alimentaires',
|
451 |
470 |
name='read-dietcode-list',
|
452 |
471 |
perm='can_access',
|
453 |
472 |
parameters={
|
454 |
473 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
455 |
474 |
'q': {'description': 'Recherche en texte intégral'},
|
|
475 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
456 |
476 |
},
|
457 |
477 |
)
|
458 |
|
def read_dietcode_list(self, request, id=None, q=None):
|
459 |
|
return {'data': self.get_referential_list('DietCode', id, q)}
|
|
478 |
def read_dietcode_list(self, request, id=None, q=None, limit=None):
|
|
479 |
return {'data': self.get_referential_list('DietCode', id, q, limit)}
|
460 |
480 |
|
461 |
481 |
@endpoint(
|
462 |
482 |
display_category='Famille',
|
463 |
483 |
description='Liste des organismes (CAF)',
|
464 |
484 |
name='read-organ-list',
|
465 |
485 |
perm='can_access',
|
466 |
486 |
parameters={
|
467 |
487 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
468 |
488 |
'q': {'description': 'Recherche en texte intégral'},
|
|
489 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
469 |
490 |
},
|
470 |
491 |
)
|
471 |
|
def read_organ_list(self, request, id=None, q=None):
|
472 |
|
return {'data': self.get_referential_list('Organ', id, q)}
|
|
492 |
def read_organ_list(self, request, id=None, q=None, limit=None):
|
|
493 |
return {'data': self.get_referential_list('Organ', id, q, limit)}
|
473 |
494 |
|
474 |
495 |
@endpoint(
|
475 |
496 |
display_category='Famille',
|
476 |
497 |
description="Liste des projet d'accueil individualisés",
|
477 |
498 |
name='read-pai-list',
|
478 |
499 |
perm='can_access',
|
479 |
500 |
parameters={
|
480 |
501 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
481 |
502 |
'q': {'description': 'Recherche en texte intégral'},
|
|
503 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
482 |
504 |
},
|
483 |
505 |
)
|
484 |
|
def read_pai_list(self, request, id=None, q=None):
|
485 |
|
return {'data': self.get_referential_list('PAI', id, q)}
|
|
506 |
def read_pai_list(self, request, id=None, q=None, limit=None):
|
|
507 |
return {'data': self.get_referential_list('PAI', id, q, limit)}
|
486 |
508 |
|
487 |
509 |
@endpoint(
|
488 |
510 |
display_category='Famille',
|
489 |
511 |
description='liste des qualités du référenciel',
|
490 |
512 |
name='read-quality-list',
|
491 |
513 |
perm='can_access',
|
492 |
514 |
parameters={
|
493 |
515 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
494 |
516 |
'q': {'description': 'Recherche en texte intégral'},
|
|
517 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
495 |
518 |
},
|
496 |
519 |
)
|
497 |
|
def read_quality_list(self, request, id=None, q=None):
|
498 |
|
return {'data': self.get_referential_list('Quality', id, q)}
|
|
520 |
def read_quality_list(self, request, id=None, q=None, limit=None):
|
|
521 |
return {'data': self.get_referential_list('Quality', id, q, limit)}
|
499 |
522 |
|
500 |
523 |
@endpoint(
|
501 |
524 |
display_category='Famille',
|
502 |
525 |
description='Liste des quotients',
|
503 |
526 |
name='read-quotient-list',
|
504 |
527 |
perm='can_access',
|
505 |
528 |
parameters={
|
506 |
529 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
507 |
530 |
'q': {'description': 'Recherche en texte intégral'},
|
|
531 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
508 |
532 |
},
|
509 |
533 |
)
|
510 |
|
def read_quotient_list(self, request, id=None, q=None):
|
511 |
|
return {'data': self.get_referential_list('Quotient', id, q)}
|
|
534 |
def read_quotient_list(self, request, id=None, q=None, limit=None):
|
|
535 |
return {'data': self.get_referential_list('Quotient', id, q, limit)}
|
512 |
536 |
|
513 |
537 |
@endpoint(
|
514 |
538 |
display_category='Famille',
|
515 |
539 |
description='Liste des sexes',
|
516 |
540 |
name='read-sex-list',
|
517 |
541 |
perm='can_access',
|
518 |
542 |
parameters={
|
519 |
543 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
520 |
544 |
'q': {'description': 'Recherche en texte intégral'},
|
|
545 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
521 |
546 |
},
|
522 |
547 |
)
|
523 |
|
def read_sex_list(self, request, id=None, q=None):
|
524 |
|
return {'data': self.get_referential_list('Sex', id, q)}
|
|
548 |
def read_sex_list(self, request, id=None, q=None, limit=None):
|
|
549 |
return {'data': self.get_referential_list('Sex', id, q, limit)}
|
525 |
550 |
|
526 |
551 |
@endpoint(
|
527 |
552 |
display_category='Famille',
|
528 |
553 |
description='liste des situations',
|
529 |
554 |
name='read-situation-list',
|
530 |
555 |
perm='can_access',
|
531 |
556 |
parameters={
|
532 |
557 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
533 |
558 |
'q': {'description': 'Recherche en texte intégral'},
|
|
559 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
534 |
560 |
},
|
535 |
561 |
)
|
536 |
|
def read_situation_list(self, request, id=None, q=None):
|
537 |
|
return {'data': self.get_referential_list('Situation', id, q)}
|
|
562 |
def read_situation_list(self, request, id=None, q=None, limit=None):
|
|
563 |
return {'data': self.get_referential_list('Situation', id, q, limit)}
|
538 |
564 |
|
539 |
565 |
@endpoint(
|
540 |
566 |
display_category='Famille',
|
541 |
567 |
description='Liste des vaccins',
|
542 |
568 |
name='read-vaccin-list',
|
543 |
569 |
perm='can_access',
|
544 |
570 |
parameters={
|
545 |
571 |
'id': {'description': 'Identifiant de l’enregistrement'},
|
546 |
572 |
'q': {'description': 'Recherche en texte intégral'},
|
|
573 |
'limit': {'description': 'Nombre maximal de résultats; doit être inférieur à 20.'},
|
547 |
574 |
},
|
548 |
575 |
)
|
549 |
|
def read_vaccin_list(self, request, id=None, q=None):
|
550 |
|
return {'data': self.get_referential_list('Vaccin', id, q)}
|
|
576 |
def read_vaccin_list(self, request, id=None, q=None, limit=None):
|
|
577 |
return {'data': self.get_referential_list('Vaccin', id, q, limit)}
|
551 |
578 |
|
552 |
579 |
@endpoint(
|
553 |
580 |
display_category='Famille',
|
554 |
581 |
description='Lier un compte usager à une famille',
|
555 |
582 |
perm='can_access',
|
556 |
583 |
parameters={'NameID': {'description': 'Publik NameID'}},
|
557 |
584 |
post={'request_body': {'schema': {'application/json': schemas.LINK_SCHEMA}}},
|
558 |
585 |
)
|