initial draft

This commit is contained in:
Frédéric Péters 2016-01-19 15:32:03 +01:00
parent 05503dd4ca
commit e51fc22ca5
12 changed files with 433 additions and 0 deletions

7
MANIFEST.in Normal file
View File

@ -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

18
README Normal file
View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.
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'

View File

@ -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 <http://www.gnu.org/licenses/>.
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)

View File

@ -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 <http://www.gnu.org/licenses/>.
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'

View File

@ -0,0 +1,8 @@
{% extends "passerelle/manage.html" %}
{% block breadcrumb %}
{{ block.super }}
{% if object.id %}
<a href="{% url 'paris-poc-gru-view' slug=object.slug %}">{{ object.title }}</a>
{% endif %}
{% endblock %}

View File

@ -0,0 +1,16 @@
{% extends "passerelle_paris_poc_gru/base.html" %}
{% load i18n %}
{% block appbar %}
<h2>Paris POC GRU - {{ 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,36 @@
{% extends "passerelle_paris_poc_gru/base.html" %}
{% load i18n passerelle %}
{% block appbar %}
<h2>Paris POC GRU - {{ object.title }}</h2>
{% if perms.passerelle_paris_poc_gru.change_passerelle_paris_poc_gru %}
<a rel="popup" class="button" href="{% url 'paris-poc-gru-edit' slug=object.slug %}">{% trans 'edit' %}</a>
{% endif %}
{% if perms.passerelle_paris_poc_gru.delete_passerelle_paris_poc_gru %}
<a rel="popup" class="button" href="{% url 'paris-poc-gru-delete' slug=object.slug %}">{% trans 'delete' %}</a>
{% endif %}
{% endblock %}
{% block content %}
<p>
</p>
<div>
<h3>{% trans 'Endpoint' %}</h3>
<ul>
<li><a href="{% url 'paris-poc-gru-endpoint' slug=object.slug %}">{{ site_base_uri }}{% url 'paris-poc-gru-endpoint' slug=object.slug %}</a>
</li>
</ul>
</div>
{% if perms.base.view_accessright %}
<div>
<h3>{% trans "Security" %}</h3>
{% access_rights_table resource=object permission='can_access' %}
{% endif %}
</div>
{% endblock %}

View File

@ -0,0 +1,34 @@
{% extends "passerelle_paris_poc_gru/base.html" %}
{% load i18n %}
{% block more-user-links %}
{{ block.super }}
{% if not object.id %}
<a href="{% url 'paris-poc-gru-add' %}">{% trans 'Add Paris POC GRU Connector' %}</a>
{% endif %}
{% endblock %}
{% block appbar %}
<h2>Paris POC GRU - {% 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,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 <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,-]+)/$', ParisPocGruDetailView.as_view(), name='paris-poc-gru-view'),
url(r'^(?P<slug>[\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<slug>[\w,-]+)/edit$', ParisPocGruUpdateView.as_view(), name='paris-poc-gru-edit'),
url(r'^(?P<slug>[\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))),
)
)

View File

@ -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 <http://www.gnu.org/licenses/>.
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, {})

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_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,
}
)