SUP-10637, SUP-10635 : use new lisrue webservice for Liege streets and Belgium streets.
This commit is contained in:
parent
7ecd840888
commit
6337bc8d20
|
@ -29,7 +29,7 @@ from passerelle.utils.api import endpoint
|
|||
class ImioLiegeLisrue(BaseResource):
|
||||
PROFILE_CHOICES = (
|
||||
('LIEGE','Liege'),
|
||||
('LIEGE_BETA','Liege lisrue2 beta'),
|
||||
('LIEGE_V2','Liege lisrue2'),
|
||||
('NAMUR','Namur'),
|
||||
)
|
||||
service_url = models.CharField(max_length=128, blank=False,
|
||||
|
@ -63,20 +63,23 @@ class ImioLiegeLisrue(BaseResource):
|
|||
@endpoint()
|
||||
def voies(self, request, q=None, **kwargs):
|
||||
url = self.service_url
|
||||
if self.include_all_of_belgium:
|
||||
url += 'jsonlisrue/'
|
||||
else:
|
||||
if self.profile == 'LIEGE_BETA':
|
||||
if self.profile == 'LIEGE_V2':
|
||||
if self.include_all_of_belgium:
|
||||
url += 'jsonruebelgique/findByValue?indexName=RUE&startResult=0&maxResult=30&value='
|
||||
else:
|
||||
url += 'jsonlgrue2com/'
|
||||
else:
|
||||
if self.include_all_of_belgium:
|
||||
url += 'jsonlisrue/'
|
||||
else:
|
||||
url += 'jsonlisrue2/'
|
||||
|
||||
if q:
|
||||
q = unicodedata.normalize('NFKD', request.GET['q']).encode('ascii', 'ignore')
|
||||
url += q.lower()
|
||||
|
||||
result = requests.get(url, headers={'Accept': 'application/json'},
|
||||
verify=self.verify_cert).json()
|
||||
if result.has_key('data'):
|
||||
result['rues'] = result.pop('data')
|
||||
if isinstance(result['rues'], list):
|
||||
lisrues = result['rues']
|
||||
elif isinstance(result['rues'], dict) and 'return' in result['rues']:
|
||||
|
@ -89,8 +92,8 @@ class ImioLiegeLisrue(BaseResource):
|
|||
streets = []
|
||||
known_street_labels = {}
|
||||
for item in lisrues:
|
||||
if item.get('rue'):
|
||||
street_label = item.get('rue')
|
||||
if item.get('rue') or item.get('libelle'):
|
||||
street_label = item.get('rue') or item.get('libelle')
|
||||
elif item.get('libelleMinuscule'):
|
||||
street_label = '%s %s' % (
|
||||
item.get('particuleMinuscule') or '',
|
||||
|
@ -105,19 +108,16 @@ class ImioLiegeLisrue(BaseResource):
|
|||
else:
|
||||
street_label = street_label.strip()
|
||||
|
||||
if (self.profile == 'LIEGE_BETA'):
|
||||
streets.append({
|
||||
'id': item.get('codeRue') or item.get('codeStreet'),
|
||||
'text': street_label
|
||||
})
|
||||
if (self.profile == 'LIEGE_V2'):
|
||||
if item.get('statutVO') is not None and item.get('statutVO').get('code') == '1':
|
||||
streets.append({
|
||||
'id': item.get('codeRue'),
|
||||
'text': street_label,
|
||||
'codeCommissariat': item.get('commissariat').get('codeCommissariat') if item.get('commissariat') else '',
|
||||
'libelleCommissariat': item.get('commissariat').get('libelleCommissariat') if item.get('commissariat') else ''
|
||||
})
|
||||
else:
|
||||
streets.append({
|
||||
'id': item.get('codeRue'),
|
||||
'text': street_label,
|
||||
})
|
||||
return {'data': streets}
|
||||
|
||||
@endpoint()
|
||||
|
|
Loading…
Reference in New Issue