general: make connectors work without appconfigs (#11201)

This commit is contained in:
Frédéric Péters 2016-06-05 17:05:55 +02:00
parent e644b3cfc8
commit 78e998eb05
20 changed files with 66 additions and 528 deletions

View File

@ -1,32 +0,0 @@
# passerelle - uniform access to multiple data sources and services
# 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.apps.base_adresse'
label = 'base_adresse'
url_prefix = 'base_adresse'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
def get_connector_model(self):
from . import models
return models.BaseAdresse
default_app_config = 'passerelle.apps.base_adresse.AppConfig'

View File

@ -1,31 +0,0 @@
# passerelle - uniform access to multiple data sources and services
# 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 = 'bdp'
label = 'bdp'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
def get_connector_model(self):
from . import models
return models.Bdp
default_app_config = 'bdp.AppConfig'

View File

@ -1,31 +0,0 @@
# passerelle - uniform access to multiple data sources and services
# 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 = 'clicrdv'
label = 'clicrdv'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
def get_connector_model(self):
from . import models
return models.ClicRdv
default_app_config = 'clicrdv.AppConfig'

View File

@ -1,31 +0,0 @@
# passerelle - uniform access to multiple data sources and services
# 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 = 'concerto'
label = 'concerto'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
def get_connector_model(self):
from . import models
return models.Concerto
default_app_config = 'concerto.AppConfig'

View File

@ -1,31 +0,0 @@
# passerelle - uniform access to multiple data sources and services
# 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 = 'gdc'
label = 'gdc'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
def get_connector_model(self):
from . import models
return models.Gdc
default_app_config = 'gdc.AppConfig'

View File

@ -1,31 +0,0 @@
# passerelle - uniform access to multiple data sources and services
# 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 = 'mobyt'
label = 'mobyt'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
def get_connector_model(self):
from . import models
return models.MobytSMSGateway
default_app_config = 'mobyt.AppConfig'

View File

@ -1,31 +0,0 @@
# passerelle - uniform access to multiple data sources and services
# 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 = 'orange'
label = 'orange'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
def get_connector_model(self):
from . import models
return models.OrangeSMSGateway
default_app_config = 'orange.AppConfig'

View File

@ -1,31 +0,0 @@
# passerelle - uniform access to multiple data sources and services
# 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 = 'oxyd'
label = 'oxyd'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
def get_connector_model(self):
from . import models
return models.OxydSMSGateway
default_app_config = 'oxyd.AppConfig'

View File

@ -0,0 +1,65 @@
# passerelle - uniform access to multiple data sources and services
# 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
from django.apps import apps
from django.utils.module_loading import import_string
class ConnectorAppMixin(object):
def get_connector_model(self):
return self._connector_model
def get_after_urls(self):
try:
return import_string('%s.urls.urlpatterns' % self.name)
except ImportError:
return None
class ConnectorAppConfig(ConnectorAppMixin, django.apps.AppConfig):
pass
class AppConfig(django.apps.AppConfig):
name = 'passerelle.base'
def ready(self):
# once all applications are ready, go through them and mark them as
# connectors if they have a get_connector_model() method or a model
# that inherits from BaseResource.
from .models import BaseResource
for app in apps.get_app_configs():
connector_model = None
if hasattr(app, 'get_connector_model'):
connector_model = app.get_connector_model()
else:
for model in app.get_models():
if issubclass(model, BaseResource):
connector_model = model
app._connector_model = model
break
if not connector_model:
continue
if app.__class__ is django.apps.AppConfig:
# switch class if it's an application without a custom
# appconfig.
app.__class__ = ConnectorAppConfig
else:
# add lixin to base classes if it's an application with a
# custom appconfig.
app.__class__.__bases__ = (ConnectorAppMixin,) + app.__class__.__bases__
default_app_config = 'passerelle.base.AppConfig'

View File

@ -1,27 +0,0 @@
# passerelle.contrib.agoraplus
# Copyright (C) 2015 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.contrib.agoraplus'
label = 'agoraplus'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
default_app_config = 'passerelle.contrib.agoraplus.AppConfig'

View File

@ -1,27 +0,0 @@
# passerelle.contrib.fake_family
# Copyright (C) 2015 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.contrib.fake_family'
label = 'fake_family'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
default_app_config = 'passerelle.contrib.fake_family.AppConfig'

View File

@ -1,27 +0,0 @@
# Passerelle - uniform access to data and services
# Copyright (C) 2015 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.contrib.iparapheur'
label = 'iparapheur'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
default_app_config = 'passerelle.contrib.iparapheur.AppConfig'

View File

@ -1,27 +0,0 @@
# passerelle.contrib.maarch
# Copyright (C) 2015 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.contrib.maarch'
label = 'maarch'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
default_app_config = 'passerelle.contrib.maarch.AppConfig'

View File

@ -1,27 +0,0 @@
# Passerelle - uniform access to data and services
# Copyright (C) 2015 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.contrib.meyzieu_newsletters'
label = 'meyzieu_newsletters'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
default_app_config = 'passerelle.contrib.meyzieu_newsletters.AppConfig'

View File

@ -1,27 +0,0 @@
# passerelle.contrib.seisin_by_email
# Copyright (C) 2015 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.contrib.seisin_by_email'
label = 'seisin_by_email'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
default_app_config = 'passerelle.contrib.seisin_by_email.AppConfig'

View File

@ -1,27 +0,0 @@
# Passerelle - uniform access to data and services
# Copyright (C) 2015 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.contrib.solis_apa'
label = 'solis_apa'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
default_app_config = 'passerelle.contrib.solis_apa.AppConfig'

View File

@ -1,31 +0,0 @@
# passerelle - uniform access to multiple data sources and services
# 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.contrib.stub_invoices'
label = 'stub_invoices'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
def get_connector_model(self):
from . import models
return models.StubInvoicesConnector
default_app_config = 'passerelle.contrib.stub_invoices.AppConfig'

View File

@ -1,27 +0,0 @@
# passerelle.contrib.teamnet_axel
# Copyright (C) 2015 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.contrib.teamnet_axel'
label = 'teamnet_axel'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
default_app_config = 'passerelle.contrib.teamnet_axel.AppConfig'

View File

@ -1,31 +0,0 @@
# passerelle - uniform access to multiple data sources and services
# Copyright (C) 2015 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.contrib.tlmcom'
label = 'tlmcom'
def get_after_urls(self):
from . import urls
return urls.urlpatterns
def get_connector_model(self):
from . import models
return models.TlmCom
default_app_config = 'passerelle.contrib.tlmcom.AppConfig'

View File

@ -27,7 +27,7 @@ def register_apps_urls(urlpatterns):
before_urls = []
after_urls = []
for app in apps.get_app_configs():
url_prefix = '^%s/' % getattr(app, 'url_prefix', app.label.replace('_', '-'))
url_prefix = '^%s/' % app.label.replace('_', '-')
if hasattr(app, 'get_before_urls'):
urls = app.get_before_urls()
if urls: