From e51fc22ca5b4b2cb3632343533b678e1531f0716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 19 Jan 2016 15:32:03 +0100 Subject: [PATCH] initial draft --- MANIFEST.in | 7 ++ README | 18 +++ passerelle_paris_poc_gru/__init__.py | 26 +++++ passerelle_paris_poc_gru/forms.py | 30 +++++ passerelle_paris_poc_gru/models.py | 42 +++++++ .../passerelle_paris_poc_gru/base.html | 8 ++ .../parispocgru_confirm_delete.html | 16 +++ .../parispocgru_detail.html | 36 ++++++ .../parispocgru_form.html | 34 ++++++ passerelle_paris_poc_gru/urls.py | 43 +++++++ passerelle_paris_poc_gru/views.py | 68 ++++++++++++ setup.py | 105 ++++++++++++++++++ 12 files changed, 433 insertions(+) create mode 100644 MANIFEST.in create mode 100644 README create mode 100644 passerelle_paris_poc_gru/__init__.py create mode 100644 passerelle_paris_poc_gru/forms.py create mode 100644 passerelle_paris_poc_gru/models.py create mode 100644 passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/base.html create mode 100644 passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_confirm_delete.html create mode 100644 passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_detail.html create mode 100644 passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_form.html create mode 100644 passerelle_paris_poc_gru/urls.py create mode 100644 passerelle_paris_poc_gru/views.py create mode 100644 setup.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..b655195 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,7 @@ +recursive-include passerelle_paris_poc_gru/static *.css *.png +recursive-include passerelle_paris_poc_gru/templates *.html *.txt +recursive-include passerelle_paris_poc_gru/locale *.po *.mo +include MANIFEST.in +include COPYING +include VERSION +include README diff --git a/README b/README new file mode 100644 index 0000000..e93e825 --- /dev/null +++ b/README @@ -0,0 +1,18 @@ +Passerelle connector for Paris POC GRU +====================================== + +Installation +------------ + + - add to Passerelle installed apps settings: + INSTALLED_APPS += ('passerelle_paris_poc_gru',) + + - enable module: + PASSERELLE_APP_PASSERELLE_POC_GRU_ENABLED = True + + +Usage +----- + + - create and configure new connector + - Title/description: whatever you want diff --git a/passerelle_paris_poc_gru/__init__.py b/passerelle_paris_poc_gru/__init__.py new file mode 100644 index 0000000..57c2b35 --- /dev/null +++ b/passerelle_paris_poc_gru/__init__.py @@ -0,0 +1,26 @@ +# passerelle - uniform access to multiple data sources and services +# Copyright (C) 2015-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 . + +import django.apps + +class AppConfig(django.apps.AppConfig): + name = 'passerelle_paris_poc_gru' + + def get_after_urls(self): + from . import urls + return urls.urlpatterns + +default_app_config = 'passerelle_paris_poc_gru.AppConfig' diff --git a/passerelle_paris_poc_gru/forms.py b/passerelle_paris_poc_gru/forms.py new file mode 100644 index 0000000..b8ad2be --- /dev/null +++ b/passerelle_paris_poc_gru/forms.py @@ -0,0 +1,30 @@ +# passerelle - uniform access to multiple data sources and services +# Copyright (C) 2015-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 . + +from django.utils.text import slugify +from django import forms + +from .models import ParisPocGru + +class ParisPocGruForm(forms.ModelForm): + class Meta: + model = ParisPocGru + exclude = ('slug', 'users') + + def save(self, commit=True): + if not self.instance.slug: + self.instance.slug = slugify(self.instance.title) + return super(ParisPocGruForm, self).save(commit=commit) diff --git a/passerelle_paris_poc_gru/models.py b/passerelle_paris_poc_gru/models.py new file mode 100644 index 0000000..61088dd --- /dev/null +++ b/passerelle_paris_poc_gru/models.py @@ -0,0 +1,42 @@ +# passerelle - uniform access to multiple data sources and services +# Copyright (C) 2015-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 . + +from django.core.urlresolvers import reverse +from django.utils.translation import ugettext_lazy as _ + +from passerelle.base.models import BaseResource + + +class ParisPocGru(BaseResource): + category = _('Business Process Connectors') + + class Meta: + verbose_name = _('Paris Poc GRU') + + def get_absolute_url(self): + return reverse('paris-poc-gru-view', kwargs={'slug': self.slug}) + + @classmethod + def get_add_url(cls): + return reverse('paris-poc-gru-add') + + @classmethod + def get_verbose_name(cls): + return cls._meta.verbose_name + + @classmethod + def get_icon_class(cls): + return 'ressources' diff --git a/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/base.html b/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/base.html new file mode 100644 index 0000000..1ebcae9 --- /dev/null +++ b/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/base.html @@ -0,0 +1,8 @@ +{% extends "passerelle/manage.html" %} + +{% block breadcrumb %} +{{ block.super }} +{% if object.id %} +{{ object.title }} +{% endif %} +{% endblock %} diff --git a/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_confirm_delete.html b/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_confirm_delete.html new file mode 100644 index 0000000..6ec06e3 --- /dev/null +++ b/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_confirm_delete.html @@ -0,0 +1,16 @@ +{% extends "passerelle_paris_poc_gru/base.html" %} +{% load i18n %} + +{% block appbar %} +

Paris POC GRU - {{ object.title }}

+{% endblock %} + +{% block content %} +
+ {% csrf_token %} +
+ + {% trans 'Cancel' %} +
+
+{% endblock %} diff --git a/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_detail.html b/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_detail.html new file mode 100644 index 0000000..2971913 --- /dev/null +++ b/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_detail.html @@ -0,0 +1,36 @@ +{% extends "passerelle_paris_poc_gru/base.html" %} +{% load i18n passerelle %} + +{% block appbar %} +

Paris POC GRU - {{ object.title }}

+{% if perms.passerelle_paris_poc_gru.change_passerelle_paris_poc_gru %} +{% trans 'edit' %} +{% endif %} +{% if perms.passerelle_paris_poc_gru.delete_passerelle_paris_poc_gru %} +{% trans 'delete' %} +{% endif %} +{% endblock %} + +{% block content %} +

+

+ +
+

{% trans 'Endpoint' %}

+ +
+ +{% if perms.base.view_accessright %} +
+

{% trans "Security" %}

+ +{% access_rights_table resource=object permission='can_access' %} + +{% endif %} + +
+ +{% endblock %} diff --git a/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_form.html b/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_form.html new file mode 100644 index 0000000..ac002af --- /dev/null +++ b/passerelle_paris_poc_gru/templates/passerelle_paris_poc_gru/parispocgru_form.html @@ -0,0 +1,34 @@ +{% extends "passerelle_paris_poc_gru/base.html" %} +{% load i18n %} + +{% block more-user-links %} +{{ block.super }} +{% if not object.id %} +{% trans 'Add Paris POC GRU Connector' %} +{% endif %} +{% endblock %} + +{% block appbar %} +

Paris POC GRU - {% if object.id %}{{ object.title }}{% else %}{% trans 'New' %}{% endif %}

+{% endblock %} + +{% block content %} + +
+
+ {% csrf_token %} + {{ form.as_p }} +
+ {% block buttons %} +
+ + {% if object.id %} + {% trans 'Cancel' %} + {% else %} + {% trans 'Cancel' %} + {% endif %} +
+ {% endblock %} +
+ +{% endblock %} diff --git a/passerelle_paris_poc_gru/urls.py b/passerelle_paris_poc_gru/urls.py new file mode 100644 index 0000000..84078c2 --- /dev/null +++ b/passerelle_paris_poc_gru/urls.py @@ -0,0 +1,43 @@ +# passerelle - uniform access to multiple data sources and services +# Copyright (C) 2015-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 . + +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[\w,-]+)/$', ParisPocGruDetailView.as_view(), name='paris-poc-gru-view'), + url(r'^(?P[\w,-]+)/endpoint/$', EndpointView.as_view(), name='paris-poc-gru-endpoint'), +) + +management_urlpatterns = patterns('', + url(r'^add$', ParisPocGruCreateView.as_view(), name='paris-poc-gru-add'), + url(r'^(?P[\w,-]+)/edit$', ParisPocGruUpdateView.as_view(), name='paris-poc-gru-edit'), + url(r'^(?P[\w,-]+)/delete$', ParisPocGruDeleteView.as_view(), name='paris-poc-gru-delete'), +) + +urlpatterns = required( + app_enabled('passerelle_paris_poc_gru'), + patterns('', + url(r'^paris-poc-gru/', include(public_urlpatterns)), + url(r'^manage/paris-poc-gru/', + decorated_includes(login_required, include(management_urlpatterns))), + ) +) diff --git a/passerelle_paris_poc_gru/views.py b/passerelle_paris_poc_gru/views.py new file mode 100644 index 0000000..942c052 --- /dev/null +++ b/passerelle_paris_poc_gru/views.py @@ -0,0 +1,68 @@ +# passerelle - uniform access to multiple data sources and services +# Copyright (C) 2015-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 . + +import datetime +import json + +from django.core.files.storage import default_storage +from django.core.urlresolvers import reverse +from django.utils.decorators import method_decorator +from django.views.decorators.csrf import csrf_exempt +from django.views.generic.detail import SingleObjectMixin, DetailView +from django.views.generic.edit import CreateView, UpdateView, DeleteView +from django.views.generic.base import View + +from passerelle import utils + +from .models import ParisPocGru +from .forms import ParisPocGruForm + +class ParisPocGruCreateView(CreateView): + model = ParisPocGru + form_class = ParisPocGruForm + template_name = 'passerelle/manage/service_form.html' + + +class ParisPocGruUpdateView(UpdateView): + model = ParisPocGru + form_class = ParisPocGruForm + + +class ParisPocGruDeleteView(DeleteView): + model = ParisPocGru + + def get_success_url(self): + return reverse('manage-home') + + +class ParisPocGruDetailView(DetailView): + model = ParisPocGru + + +class EndpointView(View, SingleObjectMixin): + model = ParisPocGru + + @method_decorator(csrf_exempt) + def dispatch(self, request, *args, **kwargs): + filename = 'paris-poc-gru-dump-%s.txt' % self.get_object().slug + with default_storage.open(filename, mode='a') as fp: + fp.write('%(datetime)s %(method)s %(qs)s\n%(body)s\n\n' % { + 'datetime': datetime.datetime.now(), + 'method': request.method, + 'qs': request.environ.get('QUERY_STRING'), + 'body': request.body, + }) + return utils.response_for_json(request, {}) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..828fdf9 --- /dev/null +++ b/setup.py @@ -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_paris_poc_gru'): + 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-paris-poc-gru', + version=get_version(), + author='Frederic Peters', + author_email='fpeters@entrouvert.com', + packages=find_packages(), + include_package_data=True, + url='https://dev.entrouvert.org/projects/paris/', + 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, + } +)