add switch to get all of belgium / to limit to Liege
This commit is contained in:
parent
2eca594b1c
commit
45ea9169dc
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('passerelle_imio_liege_lisrue', '0002_imioliegelisrue_log_level'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='imioliegelisrue',
|
||||
name='include_all_of_belgium',
|
||||
field=models.BooleanField(default=True, verbose_name='Include all of Belgium'),
|
||||
),
|
||||
]
|
|
@ -28,6 +28,8 @@ class ImioLiegeLisrue(BaseResource):
|
|||
service_url = models.CharField(max_length=128, blank=False,
|
||||
verbose_name=_('Service URL'),
|
||||
help_text=_('SIG Web Service URL (ex: https://e-services.liege.be:8443/)'))
|
||||
include_all_of_belgium = models.BooleanField(default=True,
|
||||
verbose_name=_('Include all of Belgium'))
|
||||
verify_cert = models.BooleanField(default=True,
|
||||
verbose_name=_('Check HTTPS Certificate validity'))
|
||||
|
||||
|
|
|
@ -55,7 +55,10 @@ class VoiesView(View, SingleObjectMixin):
|
|||
|
||||
def get(self, request, *args, **kwargs):
|
||||
url = self.get_object().service_url
|
||||
url += 'jsonlisrue/'
|
||||
if self.get_object().include_all_of_belgium:
|
||||
url += 'jsonlisrue/'
|
||||
else:
|
||||
url += 'jsonlisrue2/'
|
||||
|
||||
if 'q' in request.GET and request.GET['q']:
|
||||
q = unicodedata.normalize('NFKD', request.GET['q']).encode('ascii', 'ignore')
|
||||
|
@ -72,11 +75,17 @@ class VoiesView(View, SingleObjectMixin):
|
|||
|
||||
streets = []
|
||||
for item in lisrues:
|
||||
if not item.get('rue'):
|
||||
if item.get('rue'):
|
||||
street_label = item.get('rue')
|
||||
elif item.get('libelleMinuscule'):
|
||||
street_label = '%s %s' % (
|
||||
item.get('particuleMinuscule') or '',
|
||||
item.get('libelleMinuscule'))
|
||||
else:
|
||||
continue
|
||||
streets.append({
|
||||
'id': item.get('codeRue'),
|
||||
'text': item.get('rue')
|
||||
'text': street_label.strip(),
|
||||
})
|
||||
|
||||
return utils.response_for_json(request, {'data': streets})
|
||||
|
|
Loading…
Reference in New Issue