Add project
This commit is contained in:
parent
28e1f63d8e
commit
d71743dd25
|
@ -0,0 +1,7 @@
|
|||
from django import forms
|
||||
from .models import MotivationTerm
|
||||
|
||||
|
||||
class MotivationTermForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = MotivationTerm
|
|
@ -0,0 +1,58 @@
|
|||
# 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-ts1-datasources 0\n"
|
||||
"POT-Creation-Date: 2017-01-16 17:28+0100\n"
|
||||
"PO-Revision-Date: 2017-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:31
|
||||
msgid "Label"
|
||||
msgstr "Libellé"
|
||||
|
||||
#: models.py:32
|
||||
msgid "help label"
|
||||
msgstr ""
|
||||
|
||||
#: models.py:35
|
||||
msgid "Price"
|
||||
msgstr ""
|
||||
|
||||
#: models.py:36
|
||||
msgid "help price"
|
||||
msgstr ""
|
||||
|
||||
#: models.py:39
|
||||
msgid "Description"
|
||||
msgstr ""
|
||||
|
||||
#: models.py:40
|
||||
msgid "help description"
|
||||
msgstr ""
|
||||
|
||||
#: models.py:42
|
||||
msgid "Datasources manager"
|
||||
msgstr ""
|
||||
|
||||
#: models.py:45
|
||||
msgid "TS1 datasources manage Service"
|
||||
msgstr ""
|
||||
|
||||
#: templates/passerelle_imio_ts1_datasources/imiots1datasources_detail.html:7
|
||||
msgid "Listing streets:"
|
||||
msgstr ""
|
||||
|
||||
#: templates/passerelle_imio_ts1_datasources/imiots1datasources_detail.html:15
|
||||
msgid "Accessing the listings is open."
|
||||
msgstr ""
|
|
@ -0,0 +1,126 @@
|
|||
# passerelle-imio-ts1-datasources - passerelle connector to ts1 datasources import and manage
|
||||
# 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 unicodedata
|
||||
# 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
|
||||
from passerelle.utils.api import endpoint
|
||||
|
||||
|
||||
class MotivationTerm(models.Model):
|
||||
# resource = models.ForeignKey('ImioTs1Datasources')
|
||||
# strid = models.CharField(max_length=100)
|
||||
# slug = models.SlugField(_('Name (slug)'))
|
||||
text = models.CharField(max_length=100)
|
||||
price = models.CharField(max_length=4)
|
||||
description = models.TextField(max_length=500)
|
||||
|
||||
class Meta:
|
||||
ordering = ['text']
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
import ipdb;ipdb.set_trace()
|
||||
return super(MotivationTerm, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class ImioTs1Datasources(BaseResource):
|
||||
|
||||
lst_motivations_terms = [{'text': u'mon motif', 'price': 0.0, 'id': 'mon-motif', 'description': u''},
|
||||
{'text': u"Allocations d'\xe9tudes", 'price': 3.0, 'id': 'allocations-detudes', 'description': u'<p>Bla Bla</p>'},
|
||||
{'text': u'Cr\xe8che : gratuit', 'price': 0.0, 'id': 'creche', 'description': u'Cr\xe8che'},
|
||||
{'text': u'Consulat : co\xfbt 2\u20ac', 'price': 2.0, 'id': 'consulat', 'description': u'Consulat'},
|
||||
{'text': u"Bourse d'\xe9tudes : gratuit", 'price': 0.0, 'id': 'bourse-d-etudes', 'description': u"Bourse d'\xe9tudes"},
|
||||
{'text': u'Banque : co\xfbt 2\u20ac', 'price': 2.0, 'id': 'banque', 'description': u'Banque'},
|
||||
{'text': u'Avocat : co\xfbt 2\u20ac', 'price': 2.0, 'id': 'avocat', 'description': u'Avocat'},
|
||||
{'text': u'Autre : indiquer la raison dans le commentaire', 'price': 0.0, 'id': 'autre', 'description': u'Autre'},
|
||||
{'text': u'Assurance : co\xfbt 2\u20ac', 'price': 2.0, 'id': 'assurance', 'description': u'Assurance'},
|
||||
{'text': u'Allocations familiales : gratuit', 'price': 0.0, 'id': 'allocations-familiales', 'description': u'Allocations familiales'},
|
||||
{'text': u"Usage \xe0 l'\xe9tranger : co\xfbt 2\u20ac", 'price': 2.0, 'id': 'usage-etranger', 'description': u"Usage \xe0 l'\xe9tranger"},
|
||||
{'text': u'Syndicat - ONEM : gratuit', 'price': 0.0, 'id': 'syndicat', 'description': u'Syndicat'},
|
||||
{'text': u'Succession : co\xfbt 2\u20ac', 'price': 2.0, 'id': 'succession', 'description': u'Succession'},
|
||||
{'text': u'R\xe9gion Wallonne : gratuit', 'price': 0.0, 'id': 'region-wallonne', 'description': u'R\xe9gion Wallonne'},
|
||||
{'text': u'Pour mariage en Belgique : gratuit', 'price': 0.0, 'id': 'pour-mariage-belgique', 'description': u'Pour mariage en Belgique'},
|
||||
{'text': u'Pension : gratuit', 'price': 0.0, 'id': 'pension', 'description': u'Pension'},
|
||||
{'text': u'Notaire : co\xfbt 2\u20ac', 'price': 2.0, 'id': 'notaire', 'description': u'Notaire'},
|
||||
{'text': u'Mutuelle : gratuit', 'price': 0.0, 'id': 'mutuelle', 'description': u'Mutuelle'},
|
||||
{'text': u'Logement social : gratuit', 'price': 0.0, 'id': 'logement-social', 'description': u'Logement social'},
|
||||
{'text': u'Huissier : co\xfbt 2\u20ac', 'price': 2.0, 'id': 'huissier', 'description': u'Huissier'},
|
||||
{'text': u'Ecole : gratuit', 'price': 0.0, 'id': 'ecole', 'description': u'Ecole'},
|
||||
{'text': u"Demande d'emploi : gratuit", 'price': 0.0, 'id': 'demande-d-emploi', 'description': u"Demande d'emploi"}
|
||||
]
|
||||
|
||||
category = _('Datasources manager')
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('TS1 datasources manage Service')
|
||||
|
||||
@classmethod
|
||||
def get_lst_motivations_terms(cls):
|
||||
return cls.lst_motivations_terms
|
||||
|
||||
@classmethod
|
||||
def get_verbose_name(cls):
|
||||
return cls._meta.verbose_name
|
||||
|
||||
@classmethod
|
||||
def get_icon_class(cls):
|
||||
return ''
|
||||
|
||||
@classmethod
|
||||
def get_connector_slug(cls):
|
||||
return 'imio-ts1-datasources'
|
||||
|
||||
@classmethod
|
||||
def create_or_update_and_get(self, model_class, data):
|
||||
get_or_create_kwargs = {model_class._meta.pk.name: data.pop(model_class._meta.pk.name)
|
||||
}
|
||||
try:
|
||||
# get
|
||||
instance = model_class.objects.get(**get_or_create_kwargs)
|
||||
except model_class.DoesNotExist:
|
||||
# create
|
||||
instance = model_class(**get_or_create_kwargs)
|
||||
# update (or finish creating)
|
||||
for key, value in data.items():
|
||||
field = model_class._meta.get_field(key)
|
||||
if not field:
|
||||
continue
|
||||
if isinstance(field, models.ManyToManyField):
|
||||
# can't add m2m until parent is saved
|
||||
continue
|
||||
elif isinstance(field, models.ForeignKey) and hasattr(value, 'items'):
|
||||
rel_instance = self.create_or_update_and_get(field.rel.to, value)
|
||||
setattr(instance, key, rel_instance)
|
||||
else:
|
||||
setattr(instance, key, value)
|
||||
instance.save()
|
||||
# now add the m2m relations
|
||||
for field in model_class._meta.many_to_many:
|
||||
if field.name in data and hasattr(data[field.name], 'append'):
|
||||
for obj in data[field.name]:
|
||||
rel_instance = self.create_or_update_and_get(field.rel.to, obj)
|
||||
getattr(instance, field.name).add(rel_instance)
|
||||
return instance
|
||||
|
||||
@endpoint()
|
||||
def voies(self, request, q=None, **kwargs):
|
||||
pass
|
|
@ -0,0 +1,20 @@
|
|||
{% extends "passerelle/manage/service_view.html" %}
|
||||
{% load i18n passerelle %}
|
||||
|
||||
{% block content %}
|
||||
{% if object.description %}{{object.description|linebreaks}}{% endif %}
|
||||
{{object.label}}
|
||||
<br />
|
||||
|
||||
<div>
|
||||
{%for element in object.get_lst_motivations_terms%}
|
||||
{{ element.text }} - {{ element.price }} - {{ element.id }} - {{ element.description }}
|
||||
<br />
|
||||
{% endfor %}
|
||||
</div>
|
||||
<p>
|
||||
<!--csv-new-query-->
|
||||
<a class="icon-plus button" href="{% url 'motivationterm-add' connector_slug=object.slug %}">{% trans 'Add new record' %}</a>
|
||||
</p>
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,33 @@
|
|||
{% extends "passerelle/manage.html" %}
|
||||
{% load i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{{ block.super }}
|
||||
<a href="{{ resource.get_absolute_url }}">{{ resource.title }}</a>
|
||||
{% if object.id %}
|
||||
<a href="{{ object.id }}">{{ object.slug }}</a>
|
||||
{% else %}
|
||||
<a href="#">{% trans 'Add Query' %}</a>
|
||||
{% endif %}
|
||||
{% 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>
|
||||
<button>{% trans "Cancel" %}</button>
|
||||
<!--a class="cancel" href="{{ resource.get_absolute_url }}">{% trans 'Cancel' %}</a-->
|
||||
</div>
|
||||
{% endblock %}
|
||||
</form>
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,11 @@
|
|||
from django.conf.urls import patterns, include, url
|
||||
from .views import DatasourcesView, MotivationtermAddView
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^(?P<slug>[\w,-]+)/data$', DatasourcesView.as_view(), name='DatasourcesView-data'),
|
||||
)
|
||||
|
||||
management_urlpatterns = patterns('',
|
||||
url(r'^(?P<connector_slug>[\w,-]+)/motivationterm/add/',
|
||||
MotivationtermAddView.as_view(), name='motivationterm-add'),
|
||||
)
|
|
@ -0,0 +1,19 @@
|
|||
# from django.http import HttpResponseRedirect
|
||||
from django.views.generic import View, CreateView
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
|
||||
from .models import ImioTs1Datasources, MotivationTerm
|
||||
from .forms import MotivationTermForm
|
||||
|
||||
|
||||
class DatasourcesView(View, SingleObjectMixin):
|
||||
model = ImioTs1Datasources
|
||||
# form_class = DatasourcesForm
|
||||
|
||||
|
||||
# DatasourcesAddView is missing a QuerySet. Define DatasourcesAddView.model,
|
||||
# DatasourcesAddView.queryset, or override DatasourcesAddView.get_queryset().
|
||||
class MotivationtermAddView(CreateView):
|
||||
model = MotivationTerm
|
||||
form_class = MotivationTermForm
|
||||
template_name = 'passerelle_imio_ts1_datasources/motivationterm_form.html'
|
|
@ -0,0 +1,106 @@
|
|||
#! /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_ts1_datasources'):
|
||||
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-ts1-datasources',
|
||||
version=get_version(),
|
||||
author='Christophe Boulanger',
|
||||
author_email='christophe.boulanger@imio.be',
|
||||
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.5, <1.8',
|
||||
],
|
||||
zip_safe=False,
|
||||
cmdclass={
|
||||
'build': build,
|
||||
'compile_translations': compile_translations,
|
||||
'install_lib': install_lib,
|
||||
'sdist': eo_sdist,
|
||||
}
|
||||
)
|
Loading…
Reference in New Issue