update to new shorter passerelle code
This commit is contained in:
parent
6670350735
commit
b69fbfb361
|
@ -1,28 +0,0 @@
|
|||
# passerelle-imio-tax-compute - 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_tax_compute'
|
||||
verbose_name = 'Tax compute'
|
||||
|
||||
def get_after_urls(self):
|
||||
from . import urls
|
||||
return urls.urlpatterns
|
||||
|
||||
default_app_config = 'passerelle_imio_tax_compute.AppConfig'
|
|
@ -1,30 +0,0 @@
|
|||
# passerelle-imio-tax-compute - 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 ImioTsTaxCompute
|
||||
|
||||
class ImioTsTaxComputeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = ImioTsTaxCompute
|
||||
exclude = ('slug', 'users')
|
||||
|
||||
def save(self, commit=True):
|
||||
if not self.instance.slug:
|
||||
self.instance.slug = slugify(self.instance.title)
|
||||
return super(ImioTsTaxComputeForm, 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 json
|
||||
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 ImioTsTaxCompute(BaseResource):
|
||||
|
@ -31,13 +33,6 @@ class ImioTsTaxCompute(BaseResource):
|
|||
class Meta:
|
||||
verbose_name = _('Tax compute Service')
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('imio-tax-compute-view', kwargs={'slug': self.slug})
|
||||
|
||||
@classmethod
|
||||
def get_add_url(cls):
|
||||
return reverse('imio-tax-compute-add')
|
||||
|
||||
@classmethod
|
||||
def get_verbose_name(cls):
|
||||
return cls._meta.verbose_name
|
||||
|
@ -45,3 +40,19 @@ class ImioTsTaxCompute(BaseResource):
|
|||
@classmethod
|
||||
def get_icon_class(cls):
|
||||
return 'gis'
|
||||
|
||||
@classmethod
|
||||
def get_connector_slug(cls):
|
||||
return 'imio-tax-compute'
|
||||
|
||||
@endpoint(methods=['post'])
|
||||
def eval(self, request, *args, **kwargs):
|
||||
data = dict([(x, request.GET[x]) for x in request.GET.keys()])
|
||||
if request.body:
|
||||
payload = json.loads(request.body)
|
||||
data.update(payload.get("fields"))
|
||||
expression = self.formule
|
||||
code_object = compile(expression, "<string>", "exec")
|
||||
eval(code_object, data)
|
||||
result = data.get("result")
|
||||
return {'data': result}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
{% extends "passerelle/manage.html" %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{{ block.super }}
|
||||
{% if object.id %}
|
||||
<a href="{% url 'imio-tax-compute-view' slug=object.slug %}">{{ object.title }}</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -1,16 +0,0 @@
|
|||
{% extends "passerelle_imio_tax_compute/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>TaxCompute - {{ 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,41 +1,15 @@
|
|||
{% extends "passerelle_imio_tax_compute/base.html" %}
|
||||
{% extends "passerelle/manage/service_view.html" %}
|
||||
{% load i18n passerelle %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>TaxCompute - {{ object.title }}</h2>
|
||||
{% if perms.passerelle_imio_tax_compute.change_passerelle_imio_tax_compute %}
|
||||
<a rel="popup" class="button" href="{% url 'imio-tax-compute-edit' slug=object.slug %}">{% trans 'edit' %}</a>
|
||||
{% endif %}
|
||||
{% if perms.passerelle_imio_tax_compute.delete_passerelle_imio_tax_compute %}
|
||||
<a rel="popup" class="button" href="{% url 'imio-tax-compute-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-tax-compute" slug=object.slug endpoint="eval" as eval_url %}
|
||||
<ul>
|
||||
<li>{% trans 'Tax calculation:' %}
|
||||
<a href="{% url 'imio-tax-compute-eval' slug=object.slug %}">{{ site_base_uri }}{% url 'imio-tax-compute-eval' slug=object.slug %}</a>
|
||||
<li>{% trans 'Eval tax:' %}
|
||||
<a href="{{eval_url}}">{{ site_base_uri }}{{eval_url}}</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{% if perms.base.view_accessright %}
|
||||
<div>
|
||||
<h3>{% trans "Security" %}</h3>
|
||||
|
||||
<p>
|
||||
{% trans 'Accessing the listings is open.' %}
|
||||
</p>
|
||||
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block security %}
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
{% extends "passerelle_imio_tax_compute/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block more-user-links %}
|
||||
{{ block.super }}
|
||||
{% if not object.id %}
|
||||
<a href="{% url 'imio-tax-compute-add' %}">{% trans 'Add Tax compute Connector' %}</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>TaxCompute - {% 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,45 +0,0 @@
|
|||
# passerelle-imio-tax-compute - 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.views.decorators.csrf import csrf_exempt
|
||||
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-tax-compute-view'),
|
||||
|
||||
url(r'^(?P<slug>[\w,-]+)/eval/$', csrf_exempt(EvalView.as_view()), name='imio-tax-compute-eval'),
|
||||
)
|
||||
|
||||
management_urlpatterns = patterns('',
|
||||
url(r'^add$', SigCreateView.as_view(), name='imio-tax-compute-add'),
|
||||
url(r'^(?P<slug>[\w,-]+)/edit$', SigUpdateView.as_view(), name='imio-tax-compute-edit'),
|
||||
url(r'^(?P<slug>[\w,-]+)/delete$', SigDeleteView.as_view(), name='imio-tax-compute-delete'),
|
||||
)
|
||||
|
||||
urlpatterns = required(
|
||||
app_enabled('passerelle_imio_tax_compute'),
|
||||
patterns('',
|
||||
url(r'^imio-tax-compute/', include(public_urlpatterns)),
|
||||
url(r'^manage/imio-tax-compute/',
|
||||
decorated_includes(login_required, include(management_urlpatterns))),
|
||||
)
|
||||
)
|
|
@ -1,69 +0,0 @@
|
|||
# passerelle-imio-tax-compute - 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 json
|
||||
|
||||
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 ImioTsTaxCompute
|
||||
from .forms import ImioTsTaxComputeForm
|
||||
|
||||
|
||||
class SigCreateView(CreateView):
|
||||
model = ImioTsTaxCompute
|
||||
form_class = ImioTsTaxComputeForm
|
||||
template_name = 'passerelle/manage/service_form.html'
|
||||
|
||||
|
||||
class SigUpdateView(UpdateView):
|
||||
model = ImioTsTaxCompute
|
||||
form_class = ImioTsTaxComputeForm
|
||||
|
||||
|
||||
class SigDeleteView(DeleteView):
|
||||
model = ImioTsTaxCompute
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('manage-home')
|
||||
|
||||
|
||||
class SigDetailView(DetailView):
|
||||
model = ImioTsTaxCompute
|
||||
|
||||
|
||||
class EvalView(View, SingleObjectMixin):
|
||||
model = ImioTsTaxCompute
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return self.post(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
data = dict([(x, request.GET[x]) for x in request.GET.keys()])
|
||||
if request.body:
|
||||
payload = json.loads(request.body)
|
||||
data.update(payload.get("fields"))
|
||||
expression = self.get_object().formule
|
||||
code_object = compile(expression, "<string>", "exec")
|
||||
eval(code_object, data)
|
||||
result = data.get("result")
|
||||
return utils.response_for_json(request, {'data': result})
|
Loading…
Reference in New Issue