toulouse-maelis: avoir la liste des activités auquelles sont inscrit un enfants ou un résponsable légal (#75472) #143
|
@ -296,6 +296,17 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
return child
|
||||
raise APIError("no '%s' child on '%s' family" % (child_id, family_id))
|
||||
|
||||
def get_rl_or_child_raw(self, family_id, person_id):
|
||||
data = self.get_family_raw(family_id)
|
||||
if data['RL1']['num'] == person_id:
|
||||
return data['RL1']
|
||||
elif data['RL2'] and data['RL2']['num'] == person_id:
|
||||
return data['RL2']
|
||||
for child in data['childList']:
|
||||
if child['num'] == person_id:
|
||||
return child
|
||||
raise APIError("no '%s' RL or child on '%s' family" % (person_id, family_id))
|
||||
|
||||
def get_child_person_raw(self, family_id, child_id, person_id):
|
||||
data = self.get_child_raw(family_id, child_id)
|
||||
for person in data['authorizedPersonList']:
|
||||
|
@ -1229,6 +1240,54 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
response = self.call('Family', 'isChildExists', **post_data)
|
||||
return {'data': response}
|
||||
|
||||
@endpoint(
|
||||
display_category='Famille',
|
||||
description="Lister les activités auxquelles un RL ou un enfant est inscrit",
|
||||
perm='can_access',
|
||||
name='read-subscribe-activity-list',
|
||||
parameters={
|
||||
'child_id': {'description': "Numéro du représentant légal ou de l'enfant"},
|
||||
'NameID': {'description': 'Publik NameID'},
|
||||
'family_id': {'description': 'Numéro de DUI'},
|
||||
'nature': {
|
||||
'description': "Natures des activités : PERICSO, EXTRASCO ou LOISIR (toutes par défaut)",
|
||||
},
|
||||
'type_ids': {
|
||||
'description': "Codes des types des activités (tous par défaut), séparés par des virgules",
|
||||
'example_value': 'ACCSOIR,RESTSCOL',
|
||||
},
|
||||
},
|
||||
)
|
||||
def read_subscribe_activity_list(
|
||||
self, request, person_id, NameID=None, family_id=None, nature=None, type_ids=None
|
||||
):
|
||||
family_id = family_id or self.get_link(NameID).family_id
|
||||
result = self.get_rl_or_child_raw(family_id, person_id)
|
||||
if str(nature).lower() == 'perisco':
|
||||
nature_filter_codes = self.get_perisco_nature_codes()
|
||||
elif str(nature).lower() == 'extrasco':
|
||||
nature_filter_codes = self.get_extrasco_nature_codes()
|
||||
elif str(nature).lower() == 'loisir':
|
||||
nature_filter_codes = self.get_loisir_nature_codes()
|
||||
else:
|
||||
nature_filter_codes = None
|
||||
type_filter_codes = [x.strip() for x in str(type_ids or '').split(',') if x.strip()]
|
||||
|
||||
data = []
|
||||
for item in result['subscribeActivityList'] or []:
|
||||
activity_type = item.get('typeActivity')
|
||||
activity_nature = activity_type.get('natureSpec') if activity_type else None
|
||||
if type_filter_codes:
|
||||
if not activity_type or activity_type['code'] not in type_filter_codes:
|
||||
continue
|
||||
if nature_filter_codes:
|
||||
if not activity_nature or activity_nature['code'] not in nature_filter_codes:
|
||||
continue
|
||||
item['id'] = item['idActivity']
|
||||
item['text'] = item['libelle']
|
||||
data.append(item)
|
||||
return {'data': data}
|
||||
|
||||
@endpoint(
|
||||
display_category='Famille',
|
||||
description='Créer la famille',
|
||||
|
|
|
@ -1640,6 +1640,85 @@ def test_read_rl_not_found(family_service, con, app):
|
|||
assert resp.json['err_desc'] == "no '000000' RL on '1312' family"
|
||||
|
||||
|
||||
def test_read_subscribe_activity_list(family_service, con, app):
|
||||
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
|
||||
url = get_endpoint('read-subscribe-activity-list')
|
||||
|
||||
resp = app.get(url + '?family_id=1312&person_id=613880')
|
||||
assert resp.json['err'] == 0
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
|
||||
# RL2
|
||||
resp = app.get(url + '?NameID=local&person_id=613879')
|
||||
assert [(x['id'], x['text']) for x in resp.json['data']] == [
|
||||
('A10053179463', 'CSocial Adult 2021/2022 - Bijoux en cuirs 21/03/22')
|
||||
]
|
||||
|
||||
# child
|
||||
resp = app.get(url + '?NameID=local&person_id=613880')
|
||||
assert [
|
||||
(x['id'], x['text'], x['typeActivity']['natureSpec']['code'], x['typeActivity']['code'])
|
||||
for x in resp.json['data']
|
||||
] == [
|
||||
('A10049327682', 'RESTAURATION SCOLAIRE 22/23', 'R', 'RESTSCOL'),
|
||||
('A10049327686', 'CLAE MIDI 22/23', 'A', 'ACCPERI'),
|
||||
('A10049327689', 'CLAE MATIN 22/23', 'A', 'ACCMAT'),
|
||||
('A10049354913', 'SEMST2 ADL MERC. ELEM Maourine 22/23', 'X', 'EXTMERC'),
|
||||
('A10053179798', 'ECOLE DES SPORTS 22/23 SEMESTRE 2 - MULTIACTIVITES', '8', '25'),
|
||||
]
|
||||
|
||||
resp = app.get(url + '?NameID=local&person_id=613880&nature=PERISCO')
|
||||
assert resp.json['err'] == 0
|
||||
assert [
|
||||
(x['id'], x['text'], x['typeActivity']['natureSpec']['code'], x['typeActivity']['code'])
|
||||
for x in resp.json['data']
|
||||
] == [
|
||||
('A10049327682', 'RESTAURATION SCOLAIRE 22/23', 'R', 'RESTSCOL'),
|
||||
('A10049327686', 'CLAE MIDI 22/23', 'A', 'ACCPERI'),
|
||||
('A10049327689', 'CLAE MATIN 22/23', 'A', 'ACCMAT'),
|
||||
]
|
||||
|
||||
resp = app.get(url + '?NameID=local&person_id=613880&nature=EXTRASCO')
|
||||
assert [
|
||||
(x['id'], x['text'], x['typeActivity']['natureSpec']['code'], x['typeActivity']['code'])
|
||||
for x in resp.json['data']
|
||||
] == [
|
||||
('A10049354913', 'SEMST2 ADL MERC. ELEM Maourine 22/23', 'X', 'EXTMERC'),
|
||||
]
|
||||
|
||||
resp = app.get(url + '?NameID=local&person_id=613880&nature=LOISIR')
|
||||
assert [
|
||||
(x['id'], x['text'], x['typeActivity']['natureSpec']['code'], x['typeActivity']['code'])
|
||||
for x in resp.json['data']
|
||||
] == [
|
||||
('A10053179798', 'ECOLE DES SPORTS 22/23 SEMESTRE 2 - MULTIACTIVITES', '8', '25'),
|
||||
]
|
||||
|
||||
resp = app.get(url + '?NameID=local&person_id=613880&type_ids=ACCMAT')
|
||||
assert resp.json['err'] == 0
|
||||
assert [
|
||||
(x['id'], x['text'], x['typeActivity']['natureSpec']['code'], x['typeActivity']['code'])
|
||||
for x in resp.json['data']
|
||||
] == [('A10049327689', 'CLAE MATIN 22/23', 'A', 'ACCMAT')]
|
||||
|
||||
|
||||
def test_read_subscribe_activity_list_not_linked_error(con, app):
|
||||
url = get_endpoint('read-subscribe-activity-list')
|
||||
|
||||
resp = app.get(url + '?NameID=local&person_id=613880')
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'] == 'User not linked to family'
|
||||
|
||||
|
||||
def test_read_subscribe_activity_list_not_found(family_service, con, app):
|
||||
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
|
||||
url = get_endpoint('read-subscribe-activity-list')
|
||||
|
||||
resp = app.get(url + '?family_id=1312&person_id=000000')
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'] == "no '000000' RL or child on '1312' family"
|
||||
|
||||
|
||||
def test_read_person(family_service, con, app):
|
||||
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
|
||||
url = get_endpoint('read-person')
|
||||
|
|
Loading…
Reference in New Issue