From 4f34f25ba1dcfd0093f8c3d8f760655b37ed40c2 Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Sun, 26 Mar 2023 15:16:30 +0200 Subject: [PATCH] toulouse-maelis: add a school year parameter on read_subscribe_activity_list (#75552) --- passerelle/contrib/toulouse_maelis/models.py | 17 ++++++++++++++++- tests/test_toulouse_maelis.py | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/passerelle/contrib/toulouse_maelis/models.py b/passerelle/contrib/toulouse_maelis/models.py index a11cae78..5c5e596a 100644 --- a/passerelle/contrib/toulouse_maelis/models.py +++ b/passerelle/contrib/toulouse_maelis/models.py @@ -1227,10 +1227,14 @@ class ToulouseMaelis(BaseResource, HTTPResource): 'description': "Codes des types des activités (tous par défaut), séparés par des virgules", 'example_value': 'ACCSOIR,RESTSCOL', }, + 'school_year': { + 'description': 'Année scolaire (ex: 2022-2023)', + 'example_value': '2022-2023', + }, }, ) def read_subscribe_activity_list( - self, request, person_id, NameID=None, family_id=None, nature=None, type_ids=None + self, request, person_id, NameID=None, family_id=None, nature=None, type_ids=None, school_year=None ): family_id = family_id or self.get_link(NameID).family_id result = self.get_rl_or_child_raw(family_id, person_id) @@ -1254,6 +1258,17 @@ class ToulouseMaelis(BaseResource, HTTPResource): if nature_filter_codes: if not activity_nature or activity_nature['code'] not in nature_filter_codes: continue + if school_year: + school_years = set() + for unit in item['subscribesUnit']: + start_year = utils.get_reference_year_from_date(unit.get('dateStart')) + end_year = utils.get_reference_year_from_date(unit.get('dateStart')) + if not start_year or not end_year: + continue + for year in range(start_year, end_year + 1): + school_years.add('%s-%s' % (year, year + 1)) + if school_year not in school_years: + continue item['id'] = item['idActivity'] item['text'] = item['libelle'] data.append(item) diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py index b270afa5..0e9d7235 100644 --- a/tests/test_toulouse_maelis.py +++ b/tests/test_toulouse_maelis.py @@ -1633,6 +1633,21 @@ def test_read_subscribe_activity_list(family_service, con, app): for x in resp.json['data'] ] == [('A10049327689', 'CLAE MATIN 22/23', 'A', 'ACCMAT')] + resp = app.get(url + '?NameID=local&person_id=613880&school_year=2022-2023') + 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&school_year=2021-2022') + assert len(resp.json['data']) == 0 + def test_read_subscribe_activity_list_not_linked_error(con, app): url = get_endpoint('read-subscribe-activity-list')