toulouse-maelis: add endpoint to get nurseries as geojson (#74393)
This commit is contained in:
parent
be111f5bb1
commit
9233aaaede
|
@ -2796,6 +2796,55 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
nurseries = [n for n in nurseries if code_psu in [u['typeAcc'] for u in n['unitList']]]
|
||||
return {'data': nurseries}
|
||||
|
||||
@endpoint(
|
||||
display_category='Inscriptions',
|
||||
description="Obtenir un geojson avec la liste des crèches",
|
||||
name='get-nursery-geojson',
|
||||
perm='can_access',
|
||||
parameters={
|
||||
'activity_type': {'description': 'Type d\'activité.', 'example_value': 'CRECHCO'},
|
||||
'code_psu': {'description': 'Code PSU. (REGULAR par défaut)'},
|
||||
},
|
||||
)
|
||||
def get_nursery_geojson(self, request, activity_type=None, code_psu='REGULAR'):
|
||||
nurseries = self.get_referential('Nursery')
|
||||
geojson = {
|
||||
'type': 'FeatureCollection',
|
||||
'features': [],
|
||||
}
|
||||
for item in nurseries:
|
||||
if activity_type and item['activityType']['code'] != activity_type:
|
||||
continue
|
||||
if not item['place']['longitude'] or not item['place']['latitude']:
|
||||
continue
|
||||
|
||||
item['activity_id'] = item['idActivity']
|
||||
item['place_id'] = item['place']['idPlace']
|
||||
for unit in item['unitList'] or []:
|
||||
if code_psu and unit['typeAcc'] != code_psu:
|
||||
continue
|
||||
|
||||
item['unit_id'] = unit['idUnit']
|
||||
geojson['features'].append(
|
||||
{
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'coordinates': [
|
||||
float(item['place']['longitude']),
|
||||
float(item['place']['latitude']),
|
||||
],
|
||||
'type': 'Point',
|
||||
},
|
||||
'properties': {
|
||||
**item,
|
||||
'id': '%s:%s:%s' % (item['activity_id'], item['unit_id'], item['place_id']),
|
||||
'text': unit['libelle'],
|
||||
'unit': unit,
|
||||
},
|
||||
}
|
||||
)
|
||||
return geojson
|
||||
|
||||
@endpoint(
|
||||
display_category='Inscriptions',
|
||||
description="Créer une demande de place en crèche pour un enfant",
|
||||
|
|
|
@ -201,6 +201,44 @@
|
|||
</address>
|
||||
</place>
|
||||
</nurseryList>
|
||||
<nurseryList>
|
||||
<activityType>
|
||||
<code>CRECHCO</code>
|
||||
<libelle>Crèche collective</libelle>
|
||||
</activityType>
|
||||
<idActivity>M10000000001</idActivity>
|
||||
<libelle>CC AMIDONNIERS</libelle>
|
||||
<manager1>
|
||||
<lastname>THOMAS</lastname>
|
||||
<firstname>GUYLAINE</firstname>
|
||||
<phone>0561615590</phone>
|
||||
<poste>CCAS</poste>
|
||||
</manager1>
|
||||
<obs1>Quartier 1.2</obs1>
|
||||
<obs2>Secteur 1</obs2>
|
||||
<unitList>
|
||||
<idUnit>M10053212402</idUnit>
|
||||
<libelle>CC AMIDONNIERS - Réguliers</libelle>
|
||||
<typeAcc>REGULAR</typeAcc>
|
||||
</unitList>
|
||||
<unitList>
|
||||
<idUnit>M10053212403</idUnit>
|
||||
<libelle>CC AMIDONNIERS - Occasionnels</libelle>
|
||||
<typeAcc>OCCASIONAL</typeAcc>
|
||||
</unitList>
|
||||
<place>
|
||||
<idPlace>M10053212401</idPlace>
|
||||
<libelle>CC AMIDONNIERS</libelle>
|
||||
<address>
|
||||
<num>29</num>
|
||||
<street1>ALL DE BRIENNE</street1>
|
||||
<zipcode>31000</zipcode>
|
||||
<town>TOULOUSE</town>
|
||||
</address>
|
||||
<latitude>43.606099</latitude>
|
||||
<longitude>1.430282</longitude>
|
||||
</place>
|
||||
</nurseryList>
|
||||
</result>
|
||||
</ns2:readNurseryListResponse>
|
||||
</soap:Body>
|
||||
|
|
|
@ -6188,16 +6188,90 @@ def test_read_nursery_list(con, app):
|
|||
url = get_endpoint('read-nursery-list')
|
||||
resp = app.get(url)
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['data']) == 10
|
||||
assert len(resp.json['data']) == 11
|
||||
for item in resp.json['data']:
|
||||
assert 'id' in item
|
||||
assert 'text' in item
|
||||
|
||||
resp = app.get(url, params={'activity_type': 'CRECHCO'})
|
||||
assert len(resp.json['data']) == 7
|
||||
assert len(resp.json['data']) == 8
|
||||
|
||||
resp = app.get(url, params={'code_psu': 'REGULAR'})
|
||||
assert len(resp.json['data']) == 8
|
||||
assert len(resp.json['data']) == 9
|
||||
|
||||
|
||||
def test_get_nursery_geojson(con, app):
|
||||
url = get_endpoint('get-nursery-geojson')
|
||||
|
||||
params = {
|
||||
'activity_type': 'CRECHCO',
|
||||
'code_psu': 'REGULAR',
|
||||
}
|
||||
resp = app.get(url, params=params)
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['features']) == 1
|
||||
assert resp.json == {
|
||||
'type': 'FeatureCollection',
|
||||
'features': [
|
||||
{
|
||||
'type': 'Feature',
|
||||
'geometry': {'coordinates': [1.430282, 43.606099], 'type': 'Point'},
|
||||
'properties': {
|
||||
'id': 'M10000000001:M10053212402:M10053212401',
|
||||
'obs1': 'Quartier 1.2',
|
||||
'obs2': 'Secteur 1',
|
||||
'text': 'CC AMIDONNIERS - Réguliers',
|
||||
'place': {
|
||||
'address': {
|
||||
'num': 29,
|
||||
'town': 'TOULOUSE',
|
||||
'street1': 'ALL DE BRIENNE',
|
||||
'street2': None,
|
||||
'zipcode': '31000',
|
||||
'idStreet': None,
|
||||
},
|
||||
'idPlace': 'M10053212401',
|
||||
'libelle': 'CC AMIDONNIERS',
|
||||
'latitude': 43.606099,
|
||||
'libelle2': None,
|
||||
'longitude': 1.430282,
|
||||
},
|
||||
'libelle': 'CC AMIDONNIERS',
|
||||
'libelle2': None,
|
||||
'manager1': {
|
||||
'phone': '0561615590',
|
||||
'poste': 'CCAS',
|
||||
'lastname': 'THOMAS',
|
||||
'firstname': 'GUYLAINE',
|
||||
},
|
||||
'manager2': None,
|
||||
'unitList': [
|
||||
{
|
||||
'idUnit': 'M10053212402',
|
||||
'libelle': 'CC AMIDONNIERS - Réguliers',
|
||||
'typeAcc': 'REGULAR',
|
||||
},
|
||||
{
|
||||
'idUnit': 'M10053212403',
|
||||
'libelle': 'CC AMIDONNIERS - Occasionnels',
|
||||
'typeAcc': 'OCCASIONAL',
|
||||
},
|
||||
],
|
||||
'idActivity': 'M10000000001',
|
||||
'activityType': {'code': 'CRECHCO', 'libelle': 'Crèche collective'},
|
||||
'activity_id': 'M10000000001',
|
||||
'place_id': 'M10053212401',
|
||||
'unit_id': 'M10053212402',
|
||||
'unit': {
|
||||
'idUnit': 'M10053212402',
|
||||
'libelle': 'CC AMIDONNIERS - Réguliers',
|
||||
'typeAcc': 'REGULAR',
|
||||
},
|
||||
},
|
||||
}
|
||||
],
|
||||
'err': 0,
|
||||
}
|
||||
|
||||
|
||||
def test_create_nursery_demand(ape_service, con, app):
|
||||
|
|
Loading…
Reference in New Issue