First code commit (code come from passerelle-imio-liege-lisrue)

This commit is contained in:
boulch 2016-06-03 12:58:42 +02:00
commit 25a597eaa5
14 changed files with 535 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
*.pyc
local_settings.py
passerelle.sqlite3
media
/static
/passerelle_imio_tax_compute.egg-info

View File

@ -0,0 +1,28 @@
# 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'

View File

@ -0,0 +1,30 @@
# 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)

View File

@ -0,0 +1,88 @@
# French translation of passerelle-imio-tax-compute
# Copyright (C) 2016 Entr'ouvert
# This file is distributed under the same license as the
# passerelle-imio-tax-compute package.
# Frédéric Péters <fpeters@entrouvert.com>, 2016
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: passerelle-imio-tax-compute 0\n"
"POT-Creation-Date: 2016-01-16 17:28+0100\n"
"PO-Revision-Date: 2016-01-16 17:28+0100\n"
"Last-Translator: Frédéric Péters <fpeters@entrouvert.com>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: models.py:13
msgid "Service URL"
msgstr "URL du service"
#: models.py:14
msgid "SIG Web Service URL (ex: https://e-services.liege.be:8443/)"
msgstr "URL du webservice du SIG (ex: https://e-services.liege.be:8443/)"
#: models.py:16
msgid "Check HTTPS Certificate validity"
msgstr "Verification de la validité du certificat HTTPS"
#: models.py:18
msgid "Geographic information system"
msgstr "Système d'information géographique"
#: models.py:21
msgid "Tax compute Service"
msgstr "Service de calcul de taxe de Liège"
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_confirm_delete.html:12
msgid "Confirm Deletion"
msgstr "Confirmer la suppression"
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_confirm_delete.html:13
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_form.html:26
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_form.html:28
msgid "Cancel"
msgstr "Annuler"
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_detail.html:7
msgid "edit"
msgstr "modifier"
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_detail.html:10
msgid "delete"
msgstr "supprimer"
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_detail.html:20
msgid "Endpoints"
msgstr "Points d'accès"
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_detail.html:22
msgid "Listing streets:"
msgstr "Lister les rues :"
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_detail.html:25
msgid "Listing streets containing string:"
msgstr "Lister les rues contenant la chaîne :"
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_detail.html:34
msgid "Security"
msgstr "Sécurité"
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_detail.html:37
msgid "Accessing the listings is open."
msgstr "L'accès aux listes est ouvert."
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_form.html:7
msgid "Add Liege Lisrue Connector"
msgstr "Ajouter un connecteur Liege Lisrue"
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_form.html:12
msgid "New"
msgstr "Nouveau"
#: templates/passerelle_imio_tax_compute/ImioTsTaxCompute_form.html:24
msgid "Save"
msgstr "Enregistrer"

View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('base', '0002_auto_20151009_0326'),
]
operations = [
migrations.CreateModel(
name='ImioTsTaxCompute',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=50)),
('slug', models.SlugField()),
('description', models.TextField()),
('log_level', models.CharField(default=b'NOTSET', max_length=10, verbose_name='Log Level', choices=[(b'NOTSET', b'NOTSET'), (b'DEBUG', b'DEBUG'), (b'INFO', b'INFO'), (b'WARNING', b'WARNING'), (b'ERROR', b'ERROR'), (b'CRITICAL', b'CRITICAL'), (b'FATAL', b'FATAL')])),
('formule', models.TextField(verbose_name='Python code to compute taxation result')),
('users', models.ManyToManyField(to='base.ApiUser', blank=True)),
],
options={
'verbose_name': 'Tax compute Service',
},
bases=(models.Model,),
),
]

View File

@ -0,0 +1,47 @@
# 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 urlparse
import requests
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _
from passerelle.base.models import BaseResource
class ImioTsTaxCompute(BaseResource):
formule = models.TextField(verbose_name=_('Python code to compute taxation result'))
category = _('Compute Module')
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
@classmethod
def get_icon_class(cls):
return 'gis'

View File

@ -0,0 +1,8 @@
{% 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 %}

View File

@ -0,0 +1,16 @@
{% 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 %}

View File

@ -0,0 +1,41 @@
{% extends "passerelle_imio_tax_compute/base.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>
<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>
</ul>
</div>
{% if perms.base.view_accessright %}
<div>
<h3>{% trans "Security" %}</h3>
<p>
{% trans 'Accessing the listings is open.' %}
</p>
{% endif %}
</div>
{% endblock %}

View File

@ -0,0 +1,34 @@
{% 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 %}

View File

@ -0,0 +1,44 @@
# 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.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/$', 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))),
)
)

View File

@ -0,0 +1,58 @@
# 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 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 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):
result = eval(self.get_object().formule)
return utils.response_for_json(request, {'data': result})

105
setup.py Normal file
View File

@ -0,0 +1,105 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import glob
import os
import re
import subprocess
import sys
from setuptools.command.install_lib import install_lib as _install_lib
from distutils.command.build import build as _build
from distutils.command.sdist import sdist
from distutils.cmd import Command
from setuptools import setup, find_packages
class eo_sdist(sdist):
def run(self):
if os.path.exists('VERSION'):
os.remove('VERSION')
version = get_version()
version_file = open('VERSION', 'w')
version_file.write(version)
version_file.close()
sdist.run(self)
if os.path.exists('VERSION'):
os.remove('VERSION')
def get_version():
if os.path.exists('VERSION'):
version_file = open('VERSION', 'r')
version = version_file.read()
version_file.close()
return version
if os.path.exists('.git'):
p = subprocess.Popen(['git', 'describe', '--dirty', '--match=v*'], stdout=subprocess.PIPE)
result = p.communicate()[0]
if p.returncode == 0:
version = result.split()[0][1:]
version = version.replace('-', '.')
return version
return '0'
class compile_translations(Command):
description = 'compile message catalogs to MO files via django compilemessages'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
try:
from django.core.management import call_command
for path, dirs, files in os.walk('passerelle_imio_tax_compute'):
if 'locale' not in dirs:
continue
curdir = os.getcwd()
os.chdir(os.path.realpath(path))
call_command('compilemessages')
os.chdir(curdir)
except ImportError:
sys.stderr.write('!!! Please install Django >= 1.4 to build translations\n')
class build(_build):
sub_commands = [('compile_translations', None)] + _build.sub_commands
class install_lib(_install_lib):
def run(self):
self.run_command('compile_translations')
_install_lib.run(self)
setup(
name='passerelle-imio-tax-compute',
version=get_version(),
author='Frederic Peters',
author_email='fpeters@entrouvert.com',
packages=find_packages(),
include_package_data=True,
url='https://dev.entrouvert.org/projects/imio/',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
],
install_requires=['django>=1.7, <1.8',
],
zip_safe=False,
cmdclass={
'build': build,
'compile_translations': compile_translations,
'install_lib': install_lib,
'sdist': eo_sdist,
}
)