From 7e1240c0d4b654266f57a17cfbe653a00f169246 Mon Sep 17 00:00:00 2001 From: Josue Kouka Date: Fri, 22 Jan 2016 18:08:38 +0100 Subject: [PATCH] apps ws urls dynamically loaded (#9727) --- mandayejs/applications.py | 20 +++++++++++++++++++- mandayejs/sites/archimed/views.py | 6 +----- mandayejs/urls.py | 6 ++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/mandayejs/applications.py b/mandayejs/applications.py index 29690d3..1c01627 100644 --- a/mandayejs/applications.py +++ b/mandayejs/applications.py @@ -18,13 +18,24 @@ import os from importlib import import_module from django.conf import settings +from django.conf.urls import patterns, include, url +from django.http import Http404 from django.core.exceptions import ImproperlyConfigured +from django.core.urlresolvers import resolve + def get_app_settings(): module_name,app_settings = tuple(settings.SITE_APP.rsplit('.',1)) module = import_module(module_name) return getattr(module, app_settings) +def app_web_services(request, path): + app = get_app_settings() + if hasattr(app, 'urlpatterns'): + view, args, kwargs = resolve(request.path, urlconf= app) + return view(request, *args, **kwargs) + raise Http404 + # App Settings class AppSettingsMeta(type): @@ -138,10 +149,17 @@ class Archimed(AppSettings): SITE_FORCE_REDIRECT_LOCATOR = '.connectBox' - SITE_WEB_SERVICES = { + SITE_WS_ENDPOINT = { 'account_details': '/DEFAULT/Ermes/Services/ILSClient.svc/RetrieveAccount', } + urlpatterns = patterns('', + url( + r'account/(?P[\w+]*)/$', + 'mandayejs.sites.archimed.views.account', + name='archimed-account-detail'), + ) + # Arpege App Settings class Arpege(AppSettings): diff --git a/mandayejs/sites/archimed/views.py b/mandayejs/sites/archimed/views.py index 470feb4..defcad6 100644 --- a/mandayejs/sites/archimed/views.py +++ b/mandayejs/sites/archimed/views.py @@ -42,11 +42,7 @@ class AccountDetails(APIView): logger = logging.getLogger(__name__) app_settings = get_app_settings() - try: - ws_uri = app_settings.SITE_WEB_SERVICES['account_details'] - except (AttributeError,): - raise ImproperlyConfigured( - 'No SITE_WEB_SERVICES defined in your AppSettings') + ws_uri = app_settings.SITE_WS_ENDPOINT['account_details'] username = kwargs['username'] user = get_object_or_404(User, username=username) diff --git a/mandayejs/urls.py b/mandayejs/urls.py index 764421a..48ea6d5 100644 --- a/mandayejs/urls.py +++ b/mandayejs/urls.py @@ -19,6 +19,7 @@ from django.conf.urls import patterns, include, url from django.contrib import admin from django.conf import settings +from mandayejs.applications import app_web_services urlpatterns = patterns('', url(r'^_mandaye/panel$', 'mandayejs.mandaye.views.panel', name='panel'), @@ -27,12 +28,9 @@ urlpatterns = patterns('', url(r'^_mandaye/post-login/$', 'mandayejs.mandaye.views.post_login', name='post-login'), url(r'^_mandaye/post-login-do/$', 'mandayejs.mandaye.views.post_login_do', name='post-login-do'), url(r'^_mandaye/admin/', include(admin.site.urls)), + url(r'^_mandaye/ws/(?P.*)$', app_web_services) ) if 'mellon' in settings.INSTALLED_APPS: urlpatterns += patterns('', url(r'^_mandaye/accounts/mellon/', include('mellon.urls'))) -if 'mandayejs.sites.archimed' in settings.INSTALLED_APPS: - urlpatterns += patterns('', - url(r'^_mandaye/archimed/', include('mandayejs.sites.archimed.urls')), - ) -- 2.7.0.rc3