toulouse-maelis: filter subscribable school years (#83262) #395
|
@ -2632,9 +2632,29 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
display_category='Inscriptions',
|
||||
description='Lister les années scolaires',
|
||||
name='read-school-years-list',
|
||||
parameters={
|
||||
'subscribable': {
|
||||
'description': "N'afficher que les années ouvertes aux inscriptions",
|
||||
|
||||
'example_value': '0',
|
||||
},
|
||||
},
|
||||
)
|
||||
def read_school_years_list(self, request):
|
||||
return {'data': self.get_referential('YearSchool')}
|
||||
def read_school_years_list(self, request, subscribable='1'):
|
||||
subscribable = utils.strtobool(subscribable)
|
||||
referential = self.get_referential('YearSchool')
|
||||
data = []
|
||||
for item in referential:
|
||||
if subscribable is True:
|
||||
start_date = item.get('dateStartSubscribeSchool')
|
||||
end_date = item.get('dateEndSubscribeSchool')
|
||||
if not (start_date and end_date):
|
||||
continue
|
||||
start_date = parse_datetime(start_date)
|
||||
smihai
commented
`strtobool` retournera les entiers 0 ou 1, donc pas besoin de conversion en booléen ici.
nroche
commented
Ça m'a surpris aussi, mais malgré son nom, strtobool renvoi un entier. Cependant, je réalise que cette fonction va être dépréciée :
Bref, je simplifie. Ça m'a surpris aussi, mais malgré son nom, strtobool renvoi un entier.
https://github.com/python/cpython/blob/v3.11.2/Lib/distutils/util.py#L308
Cependant, je réalise que cette fonction va être dépréciée :
https://peps.python.org/pep-0632/
> For these functions, you will need to reimplement the functionality yourself.
Bref, je simplifie.
smihai
commented
Tu peux juste attendre "yes" pour vrai et considérer que tout le reste est faux. >
> Bref, je simplifie.
Tu peux juste attendre "yes" pour vrai et considérer que tout le reste est faux.
nroche
commented
J'ai finalement recopié le code pour avoir un appel relativement clair. J'ai finalement recopié le code pour avoir un appel relativement clair.
Parce que ici j'ai l'impression que ça complique la compréhension d'avoir un paramètre qui est par défaut à vrai.
|
||||
end_date = parse_datetime(end_date)
|
||||
if not (start_date <= now() <= end_date):
|
||||
continue
|
||||
data.append(item)
|
||||
return {'data': data}
|
||||
|
||||
@endpoint(
|
||||
display_category='Inscriptions',
|
||||
|
|
|
@ -17,6 +17,8 @@ from math import inf
|
|||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
json_date_format = '%Y-%m-%d'
|
||||
|
||||
|
||||
|
@ -47,3 +49,12 @@ def get_public_criterias(today, start_dob, end_dob):
|
|||
data.append((str(i), publics_txt[i]))
|
||||
break
|
||||
return data
|
||||
|
||||
|
||||
def strtobool(val):
|
||||
val = val.lower()
|
||||
if val in ('y', 'yes', 't', 'true', 'on', '1'):
|
||||
return True
|
||||
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
|
||||
return False
|
||||
raise APIError('invalid truth value %r' % val)
|
||||
|
|
|
@ -5,15 +5,20 @@
|
|||
<schoolYear>2022</schoolYear>
|
||||
<dateStartYearSchool>2022-09-01T00:00:00+02:00</dateStartYearSchool>
|
||||
<dateEndYearSchool>2023-07-07T00:00:00+02:00</dateEndYearSchool>
|
||||
<dateStartSubscribeSchool>2022-04-01T00:00:00+02:00</dateStartSubscribeSchool>
|
||||
<dateEndSubscribeSchool>2023-07-08T00:00:00+02:00</dateEndSubscribeSchool>
|
||||
<dateStartSubscribeSchool>2022-09-01T00:00:00+02:00</dateStartSubscribeSchool>
|
||||
<dateEndSubscribeSchool>2023-09-01T00:00:00+02:00</dateEndSubscribeSchool>
|
||||
</yearSchoolList>
|
||||
<yearSchoolList>
|
||||
<schoolYear>2023</schoolYear>
|
||||
<dateStartYearSchool>2023-09-01T00:00:00+02:00</dateStartYearSchool>
|
||||
<dateStartYearSchool>2023-09-04T00:00:00+02:00</dateStartYearSchool>
|
||||
<dateEndYearSchool>2024-07-07T00:00:00+02:00</dateEndYearSchool>
|
||||
<dateStartSubscribeSchool>2022-12-01T00:00:00+01:00</dateStartSubscribeSchool>
|
||||
<dateEndSubscribeSchool>2023-07-08T00:00:00+02:00</dateEndSubscribeSchool>
|
||||
<dateStartSubscribeSchool>2022-09-01T00:00:00+02:00</dateStartSubscribeSchool>
|
||||
<dateEndSubscribeSchool>2024-07-01T00:00:00+02:00</dateEndSubscribeSchool>
|
||||
</yearSchoolList>
|
||||
<yearSchoolList>
|
||||
<schoolYear>2024</schoolYear>
|
||||
<dateStartYearSchool>2024-09-01T00:00:00+02:00</dateStartYearSchool>
|
||||
<dateEndYearSchool>2025-07-07T00:00:00+02:00</dateEndYearSchool>
|
||||
</yearSchoolList>
|
||||
</ns2:readYearSchoolListResponse>
|
||||
</soap:Body>
|
||||
|
|
|
@ -5069,32 +5069,52 @@ def test_get_rl1_direct_debit_order_soap_error(family_service, invoice_service,
|
|||
)
|
||||
|
||||
|
||||
def test_read_school_year_list(con, app):
|
||||
def test_read_school_year_list(con, app, freezer):
|
||||
url = get_endpoint('read-school-years-list')
|
||||
resp = app.get(url)
|
||||
freezer.move_to('2023-11-09')
|
||||
|
||||
resp = app.get(url + '?subscribable=0')
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['data']) == 2
|
||||
assert len(resp.json['data']) == 3
|
||||
assert resp.json['data'] == [
|
||||
{
|
||||
'id': 2022,
|
||||
'text': '2022',
|
||||
'schoolYear': 2022,
|
||||
'dateStartYearSchool': '2022-09-01T00:00:00+02:00',
|
||||
'dateEndYearSchool': '2023-07-07T00:00:00+02:00',
|
||||
'dateStartSubscribeSchool': '2022-04-01T00:00:00+02:00',
|
||||
'dateEndSubscribeSchool': '2023-07-08T00:00:00+02:00',
|
||||
'dateStartYearSchool': '2022-09-01T00:00:00+02:00',
|
||||
'dateEndSubscribeSchool': '2023-09-01T00:00:00+02:00',
|
||||
'dateStartSubscribeSchool': '2022-09-01T00:00:00+02:00',
|
||||
},
|
||||
{
|
||||
'id': 2023,
|
||||
'text': '2023',
|
||||
'schoolYear': 2023,
|
||||
'dateStartYearSchool': '2023-09-01T00:00:00+02:00',
|
||||
'dateEndYearSchool': '2024-07-07T00:00:00+02:00',
|
||||
'dateStartSubscribeSchool': '2022-12-01T00:00:00+01:00',
|
||||
'dateEndSubscribeSchool': '2023-07-08T00:00:00+02:00',
|
||||
'dateStartYearSchool': '2023-09-04T00:00:00+02:00',
|
||||
'dateEndSubscribeSchool': '2024-07-01T00:00:00+02:00',
|
||||
'dateStartSubscribeSchool': '2022-09-01T00:00:00+02:00',
|
||||
},
|
||||
{
|
||||
'id': 2024,
|
||||
'text': '2024',
|
||||
'schoolYear': 2024,
|
||||
'dateEndYearSchool': '2025-07-07T00:00:00+02:00',
|
||||
'dateStartYearSchool': '2024-09-01T00:00:00+02:00',
|
||||
'dateEndSubscribeSchool': None,
|
||||
'dateStartSubscribeSchool': None,
|
||||
},
|
||||
]
|
||||
|
||||
# get only subscribable school years by default
|
||||
resp = app.get(url)
|
||||
assert resp.json['err'] == 0
|
||||
assert [x['text'] for x in resp.json['data']] == ['2023']
|
||||
|
||||
resp = app.get(url + '?subscribable=plop')
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'] == "invalid truth value 'plop'"
|
||||
|
||||
|
||||
def test_read_school_levels_list(con, app):
|
||||
url = get_endpoint('read-school-levels-list')
|
||||
|
|
Loading…
Reference in New Issue
En anglais le terme correct serait "subscriptable" il me semble.
En comparant ici, j'ai l'impression que l'idée d'inscription / souscription colle mieux à cette seconde orthographe
https://www.linguee.fr/anglais-francais/traduction/subscriptable.html
Ok, fais comme tu le sens.