gdc: adapt to new SIG street names, adding proper labels to them (#6389)
This commit is contained in:
parent
99d49e0526
commit
ae50044b9a
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import unicodedata
|
||||
|
||||
try:
|
||||
import SOAPpy
|
||||
|
@ -58,6 +59,54 @@ class ObjetsView(View, SingleObjectMixin):
|
|||
result.sort(lambda x,y: cmp(x['id'], y['id']))
|
||||
return utils.response_for_json(request, result)
|
||||
|
||||
def get_voies(service_url, insee):
|
||||
server = SOAPpy.SOAPProxy(service_url)
|
||||
soap_result = phpserialize_loads(server.getListeVoieCommune(insee)['listeVoie'])
|
||||
result = []
|
||||
prefix_map = {
|
||||
'ALL': 'ALLEE',
|
||||
'AUTO': 'AUTOROUTE',
|
||||
'AV': 'AVENUE',
|
||||
'BASS': 'BASSIN',
|
||||
'BD': 'BOULEVARD',
|
||||
'CAR': 'CARREFOUR',
|
||||
'CHE': 'CHAUSSEE',
|
||||
'COUR': 'COUR',
|
||||
'CRS': 'COURS',
|
||||
'DESC': 'DESCENTE',
|
||||
'DOM': 'DOMAINE',
|
||||
'ENCL': 'ENCLOS',
|
||||
'ESP': 'ESPLANADE',
|
||||
'ESPA': 'ESPACE',
|
||||
'GR': '', # "GR GRAND-RUE JEAN MOULIN"
|
||||
'IMP': 'IMPASSE',
|
||||
'JARD': 'JARDIN',
|
||||
'MAIL': '', # "MAIL LE GRAND MAIL"
|
||||
'PARC': 'PARC',
|
||||
'PARV': '', # "PARV PARVIS DE LA LEGION D HONNEUR"
|
||||
'PAS': 'PASSAGE',
|
||||
'PL': 'PLACE',
|
||||
'PLAN': 'PLAN',
|
||||
'PONT': 'PONT',
|
||||
'QUA': 'QUAI',
|
||||
'R': 'RUE',
|
||||
'RAMB': '', # "RAMB RAMBLA DES CALISSONS"
|
||||
'RPT': 'ROND-POINT',
|
||||
'RTE': 'ROUTE',
|
||||
'SQ': 'SQUARE',
|
||||
'TSSE': '', # "TSSE TERRASSE DES ALLEES DU BOIS"
|
||||
'TUN': 'TUNNEL',
|
||||
'VIAD': 'VIADUC',
|
||||
'VOI': 'VOIE',
|
||||
}
|
||||
for k, v in soap_result.items():
|
||||
for prefix, full in prefix_map.items():
|
||||
if v.startswith(prefix + ' '):
|
||||
v = (full + v[len(prefix):]).strip()
|
||||
result.append({'id': k, 'text': v})
|
||||
result.sort(lambda x,y: cmp(x['id'], y['id']))
|
||||
return result
|
||||
|
||||
|
||||
class VoiesView(View, SingleObjectMixin):
|
||||
model = Gdc
|
||||
|
@ -65,13 +114,8 @@ class VoiesView(View, SingleObjectMixin):
|
|||
def get(self, request, *args, **kwargs):
|
||||
if SOAPpy is None:
|
||||
raise Http404
|
||||
server = SOAPpy.SOAPProxy(self.get_object().service_url)
|
||||
insee = kwargs.get('insee')
|
||||
soap_result = phpserialize_loads(server.getListeVoieCommune(insee)['listeVoie'])
|
||||
result = []
|
||||
for k, v in soap_result.items():
|
||||
result.append({'id': k, 'text': unicode(v, 'utf-8')})
|
||||
result.sort(lambda x,y: cmp(x['id'], y['id']))
|
||||
result = get_voies(self.get_object().service_url, insee)
|
||||
return utils.response_for_json(request, result)
|
||||
|
||||
|
||||
|
@ -101,9 +145,11 @@ class PostDemandeView(View, SingleObjectMixin):
|
|||
if voie_str and not voie_id:
|
||||
# look for a voie with that name, so we can provide an identifier
|
||||
# to gdc
|
||||
voies = phpserialize_loads(server.getListeVoieCommune(insee)['listeVoie'])
|
||||
for k, v in voies.items():
|
||||
if v.lower() == voie_str.lower():
|
||||
voies = get_voies(self.get_object().service_url, insee)
|
||||
normalized_voie = unicodedata.normalize('NFKD', voie_str).encode('ascii', 'ignore').decode('ascii')
|
||||
normalized_voie = normalized_voie.upper()
|
||||
for k, v in voies:
|
||||
if v == normalized_voie or k == normalized_voie:
|
||||
voie_id = k
|
||||
break
|
||||
|
||||
|
|
Loading…
Reference in New Issue