toulouse-maelis: add a natures parameter on catalog (#74272)
gitea/passerelle/pipeline/pr-main This commit looks good Details
gitea/passerelle/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Nicolas Roche 2023-02-07 15:54:11 +01:00
parent cf96b0436a
commit 0168bf9cf2
3 changed files with 32 additions and 7 deletions

View File

@ -2169,10 +2169,19 @@ class ToulouseMaelis(BaseResource, HTTPResource):
'description': "Date de référence, utilisée pour déduire l'année scolaire",
'type': 'date',
},
'nature_ids': {
'description': "Codes des natures d'activité (par défaut les activités loisirs), séparées par des virgules",
'example_value': 'P,1,2',
},
},
)
def read_activity_list(self, request, ref_date):
def read_activity_list(self, request, ref_date, nature_ids=None):
reference_year = utils.get_reference_year_from_date(ref_date)
if not nature_ids:
# actual loisir nature codes
nature_filter_codes = ['P', 'L', 'S'] + [str(i) for i in range(1, 10)]
else:
nature_filter_codes = [x.strip() for x in nature_ids.split(',') if x.strip()]
labels = {
'nature': "Nature de l'activité",
'type': "Type d'activité",
@ -2206,7 +2215,7 @@ class ToulouseMaelis(BaseResource, HTTPResource):
for activity in activities:
activity_type = activity['activityPortail'].get('activityType')
activity_nature = activity_type.get('natureSpec') if activity_type else None
if not activity_nature or activity_nature['code'] not in ('P', 'L', 'S'):
if not activity_nature or activity_nature['code'] not in nature_filter_codes:
continue
activity['id'] = activity['activityPortail']['idAct']
activity['text'] = activity['activityPortail']['libelle']

View File

@ -19,8 +19,8 @@
<code>27</code>
<libelle>ACTIVITE REGULIERE - ART PLASTIQUE</libelle>
<natureSpec>
<code>P</code>
<libelle>Loisirs</libelle>
<code>4</code>
<libelle>ART PLASTIQUE</libelle>
</natureSpec>
</activityType>
<weeklyCalendarActivityList>

View File

@ -4853,7 +4853,10 @@ def test_read_activity_list(con, app, freezer):
freezer.move_to('2023-01-01 12:00')
url = get_endpoint('read-activity-list')
params = {'ref_date': datetime.date.today().strftime(json_date_format)}
params = {
'ref_date': datetime.date.today().strftime(json_date_format),
'nature_ids': '4,L,, S ',
}
resp = app.get(url, params=params)
assert resp.json['err'] == 0
assert len(resp.json['data']) == 4
@ -4870,7 +4873,7 @@ def test_read_activity_list(con, app, freezer):
'unit': 'N/A',
'place': 'N/A',
'criterias': {
'nature': {'text': "Nature de l'activité", 'data': {'P': 'Loisirs'}, 'order': ['P']},
'nature': {'text': "Nature de l'activité", 'data': {'4': 'ART PLASTIQUE'}, 'order': ['4']},
'type': {
'text': "Type d'activité",
'data': {'activite-reguliere': 'ACTIVITE REGULIERE'},
@ -4892,7 +4895,20 @@ def test_read_activity_list(con, app, freezer):
},
}
resp = app.get(url + '?ref_date=1970-01-01')
params['nature_ids'] = 'X,L,S'
resp = app.get(url, params=params)
assert resp.json['err'] == 0
assert len(resp.json['data']) == 0
params['nature_ids'] = ''
resp = app.get(url, params=params)
assert resp.json['err'] == 0
assert len(resp.json['data']) == 4
params['ref_date'] = '1970-01-01'
resp = app.get(url, params=params)
assert resp.json['err'] == 0
assert len(resp.json['data']) == 0
assert resp.json == {
'data': [],
'meta': {