update to new connector facilities
This commit is contained in:
parent
45ea9169dc
commit
6f09ad5af5
|
@ -1,28 +0,0 @@
|
|||
# passerelle-imio-liege-lisrue - passerelle connector to Lisrue webservice
|
||||
# Copyright (C) 2016 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import django.apps
|
||||
|
||||
class AppConfig(django.apps.AppConfig):
|
||||
|
||||
name = 'passerelle_imio_liege_lisrue'
|
||||
verbose_name = 'Liege Lisrue'
|
||||
|
||||
def get_after_urls(self):
|
||||
from . import urls
|
||||
return urls.urlpatterns
|
||||
|
||||
default_app_config = 'passerelle_imio_liege_lisrue.AppConfig'
|
|
@ -1,30 +0,0 @@
|
|||
# passerelle-imio-liege-lisrue - passerelle connector to Lisrue webservice
|
||||
# Copyright (C) 2016 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.utils.text import slugify
|
||||
from django import forms
|
||||
|
||||
from .models import ImioLiegeLisrue
|
||||
|
||||
class ImioLiegeLisrueForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = ImioLiegeLisrue
|
||||
exclude = ('slug', 'users')
|
||||
|
||||
def save(self, commit=True):
|
||||
if not self.instance.slug:
|
||||
self.instance.slug = slugify(self.instance.title)
|
||||
return super(ImioLiegeLisrueForm, self).save(commit=commit)
|
|
@ -14,6 +14,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import unicodedata
|
||||
import urlparse
|
||||
import requests
|
||||
|
||||
|
@ -22,6 +23,7 @@ from django.db import models
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.utils.api import endpoint
|
||||
|
||||
|
||||
class ImioLiegeLisrue(BaseResource):
|
||||
|
@ -38,13 +40,6 @@ class ImioLiegeLisrue(BaseResource):
|
|||
class Meta:
|
||||
verbose_name = _('Liege Lisrue Service')
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('imio-liege-lisrue-view', kwargs={'slug': self.slug})
|
||||
|
||||
@classmethod
|
||||
def get_add_url(cls):
|
||||
return reverse('imio-liege-lisrue-add')
|
||||
|
||||
@classmethod
|
||||
def get_verbose_name(cls):
|
||||
return cls._meta.verbose_name
|
||||
|
@ -52,3 +47,44 @@ class ImioLiegeLisrue(BaseResource):
|
|||
@classmethod
|
||||
def get_icon_class(cls):
|
||||
return 'gis'
|
||||
|
||||
@classmethod
|
||||
def get_connector_slug(cls):
|
||||
return 'imio-liege-lisrue'
|
||||
|
||||
@endpoint()
|
||||
def voies(self, request, q=None):
|
||||
url = self.service_url
|
||||
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 isinstance(result['rues'], list):
|
||||
lisrues = result['rues']
|
||||
elif isinstance(result['rues'], dict) and 'return' in result['rues']:
|
||||
lisrues = [result['rues']['return']]
|
||||
else:
|
||||
lisrues = []
|
||||
|
||||
streets = []
|
||||
for item in lisrues:
|
||||
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': street_label.strip(),
|
||||
})
|
||||
return {'data': streets}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
{% extends "passerelle/manage.html" %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{{ block.super }}
|
||||
{% if object.id %}
|
||||
<a href="{% url 'imio-liege-lisrue-view' slug=object.slug %}">{{ object.title }}</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -1,16 +0,0 @@
|
|||
{% extends "passerelle_imio_liege_lisrue/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>Lisrue - {{ object.title }}</h2>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<div class="buttons">
|
||||
<button>{% trans 'Confirm Deletion' %}</button>
|
||||
<a class="cancel" href="{{ object.get_absolute_url }}">{% trans 'Cancel' %}</a>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -1,44 +1,20 @@
|
|||
{% extends "passerelle_imio_liege_lisrue/base.html" %}
|
||||
{% extends "passerelle/manage/service_view.html" %}
|
||||
{% load i18n passerelle %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>Lisrue - {{ object.title }}</h2>
|
||||
{% if perms.passerelle_imio_liege_lisrue.change_passerelle_imio_liege_lisrue %}
|
||||
<a rel="popup" class="button" href="{% url 'imio-liege-lisrue-edit' slug=object.slug %}">{% trans 'edit' %}</a>
|
||||
{% endif %}
|
||||
{% if perms.passerelle_imio_liege_lisrue.delete_passerelle_imio_liege_lisrue %}
|
||||
<a rel="popup" class="button" href="{% url 'imio-liege-lisrue-delete' slug=object.slug %}">{% trans 'delete' %}</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>
|
||||
Service URL : {{ object.service_url }}
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<h3>{% trans 'Endpoints' %}</h3>
|
||||
{% block endpoints %}
|
||||
{% url "generic-endpoint" connector="imio-liege-lisrue" slug=object.slug endpoint="voies" as voies_url %}
|
||||
<ul>
|
||||
<li>{% trans 'Listing streets:' %}
|
||||
<a href="{% url 'imio-liege-lisrue-voies' slug=object.slug %}">{{ site_base_uri }}{% url 'imio-liege-lisrue-view' slug=object.slug %}voies/</a>
|
||||
<a href="{{voies_url}}">{{ site_base_uri }}{{voies_url}}</a>
|
||||
</li>
|
||||
<li>{% trans 'Listing streets containing string:' %}
|
||||
<a href="{% url 'imio-liege-lisrue-voies' slug=object.slug %}?q=com">{{ site_base_uri }}{% url 'imio-liege-lisrue-view' slug=object.slug %}voies/?q=com</a>
|
||||
<a href="{{voies_url}}?q=com">{{ site_base_uri }}{{voies_url}}?q=com</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{% if perms.base.view_accessright %}
|
||||
<div>
|
||||
<h3>{% trans "Security" %}</h3>
|
||||
{% endblock %}
|
||||
|
||||
{% block security %}
|
||||
<p>
|
||||
{% trans 'Accessing the listings is open.' %}
|
||||
</p>
|
||||
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
{% extends "passerelle_imio_liege_lisrue/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block more-user-links %}
|
||||
{{ block.super }}
|
||||
{% if not object.id %}
|
||||
<a href="{% url 'imio-liege-lisrue-add' %}">{% trans 'Add Liege Lisrue Connector' %}</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>Lisrue - {% if object.id %}{{ object.title }}{% else %}{% trans 'New' %}{% endif %}</h2>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<div id="form-content">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
</div>
|
||||
{% block buttons %}
|
||||
<div class="buttons">
|
||||
<button>{% trans "Save" %}</button>
|
||||
{% if object.id %}
|
||||
<a class="cancel" href="{{ object.get_absolute_url }}">{% trans 'Cancel' %}</a>
|
||||
{% else %}
|
||||
<a class="cancel" href="{% url 'add-connector' %}">{% trans 'Cancel' %}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
|
@ -1,44 +0,0 @@
|
|||
# passerelle-imio-liege-lisrue - passerelle connector to Lisrue webservice
|
||||
# Copyright (C) 2016 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from passerelle.urls_utils import decorated_includes, required, app_enabled
|
||||
|
||||
from views import *
|
||||
|
||||
|
||||
public_urlpatterns = patterns('',
|
||||
url(r'^(?P<slug>[\w,-]+)/$', SigDetailView.as_view(), name='imio-liege-lisrue-view'),
|
||||
|
||||
url(r'^(?P<slug>[\w,-]+)/voies/$', VoiesView.as_view(), name='imio-liege-lisrue-voies'),
|
||||
)
|
||||
|
||||
management_urlpatterns = patterns('',
|
||||
url(r'^add$', SigCreateView.as_view(), name='imio-liege-lisrue-add'),
|
||||
url(r'^(?P<slug>[\w,-]+)/edit$', SigUpdateView.as_view(), name='imio-liege-lisrue-edit'),
|
||||
url(r'^(?P<slug>[\w,-]+)/delete$', SigDeleteView.as_view(), name='imio-liege-lisrue-delete'),
|
||||
)
|
||||
|
||||
urlpatterns = required(
|
||||
app_enabled('passerelle_imio_liege_lisrue'),
|
||||
patterns('',
|
||||
url(r'^imio-liege-lisrue/', include(public_urlpatterns)),
|
||||
url(r'^manage/imio-liege-lisrue/',
|
||||
decorated_includes(login_required, include(management_urlpatterns))),
|
||||
)
|
||||
)
|
|
@ -1,91 +0,0 @@
|
|||
# passerelle-imio-liege-lisrue - passerelle connector to Lisrue webservice
|
||||
# Copyright (C) 2016 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import requests
|
||||
import unicodedata
|
||||
|
||||
from django.views.generic.detail import SingleObjectMixin, DetailView
|
||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||
from django.views.generic.base import View, RedirectView
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponseBadRequest
|
||||
|
||||
from passerelle import utils
|
||||
|
||||
from .models import ImioLiegeLisrue
|
||||
from .forms import ImioLiegeLisrueForm
|
||||
|
||||
class SigCreateView(CreateView):
|
||||
model = ImioLiegeLisrue
|
||||
form_class = ImioLiegeLisrueForm
|
||||
template_name = 'passerelle/manage/service_form.html'
|
||||
|
||||
|
||||
class SigUpdateView(UpdateView):
|
||||
model = ImioLiegeLisrue
|
||||
form_class = ImioLiegeLisrueForm
|
||||
|
||||
|
||||
class SigDeleteView(DeleteView):
|
||||
model = ImioLiegeLisrue
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('manage-home')
|
||||
|
||||
|
||||
class SigDetailView(DetailView):
|
||||
model = ImioLiegeLisrue
|
||||
|
||||
|
||||
class VoiesView(View, SingleObjectMixin):
|
||||
model = ImioLiegeLisrue
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
url = self.get_object().service_url
|
||||
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')
|
||||
url += q.lower()
|
||||
|
||||
result = requests.get(url, headers={'Accept': 'application/json'},
|
||||
verify=self.get_object().verify_cert).json()
|
||||
if isinstance(result['rues'], list):
|
||||
lisrues = result['rues']
|
||||
elif isinstance(result['rues'], dict) and 'return' in result['rues']:
|
||||
lisrues = [result['rues']['return']]
|
||||
else:
|
||||
lisrues = []
|
||||
|
||||
streets = []
|
||||
for item in lisrues:
|
||||
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': street_label.strip(),
|
||||
})
|
||||
|
||||
return utils.response_for_json(request, {'data': streets})
|
Loading…
Reference in New Issue