Projet

Général

Profil

0001-apps-ws-urls-dynamically-loaded-9727.patch

Josué Kouka, 22 janvier 2016 18:08

Télécharger (3,63 ko)

Voir les différences:

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(-)
mandayejs/applications.py
18 18
from importlib import import_module
19 19

  
20 20
from django.conf import settings
21
from django.conf.urls import patterns, include, url
22
from django.http import Http404
21 23
from django.core.exceptions import ImproperlyConfigured
24
from django.core.urlresolvers import resolve
25

  
22 26

  
23 27
def get_app_settings():
24 28
    module_name,app_settings = tuple(settings.SITE_APP.rsplit('.',1))
25 29
    module = import_module(module_name)
26 30
    return getattr(module, app_settings)
27 31

  
32
def app_web_services(request, path):
33
    app = get_app_settings()
34
    if hasattr(app, 'urlpatterns'):
35
        view, args, kwargs = resolve(request.path, urlconf= app)
36
        return view(request, *args, **kwargs)
37
    raise Http404
38

  
28 39

  
29 40
# App Settings
30 41
class AppSettingsMeta(type):
......
138 149

  
139 150
    SITE_FORCE_REDIRECT_LOCATOR = '.connectBox'
140 151

  
141
    SITE_WEB_SERVICES = {
152
    SITE_WS_ENDPOINT = {
142 153
        'account_details': '/DEFAULT/Ermes/Services/ILSClient.svc/RetrieveAccount',
143 154
    }
144 155

  
156
    urlpatterns = patterns('',
157
        url(
158
            r'account/(?P<username>[\w+]*)/$', 
159
            'mandayejs.sites.archimed.views.account', 
160
            name='archimed-account-detail'),
161
    )
162

  
145 163

  
146 164
# Arpege App Settings
147 165
class Arpege(AppSettings):
mandayejs/sites/archimed/views.py
42 42
        logger = logging.getLogger(__name__)
43 43
        app_settings = get_app_settings()
44 44
      
45
        try:
46
            ws_uri = app_settings.SITE_WEB_SERVICES['account_details']
47
        except (AttributeError,):
48
            raise ImproperlyConfigured(
49
                    'No SITE_WEB_SERVICES defined in your AppSettings') 
45
        ws_uri = app_settings.SITE_WS_ENDPOINT['account_details']
50 46

  
51 47
        username = kwargs['username']
52 48
        user = get_object_or_404(User, username=username)
mandayejs/urls.py
19 19
from django.contrib import admin
20 20
from django.conf import settings
21 21

  
22
from mandayejs.applications import app_web_services
22 23

  
23 24
urlpatterns = patterns('',
24 25
    url(r'^_mandaye/panel$', 'mandayejs.mandaye.views.panel', name='panel'),
......
27 28
    url(r'^_mandaye/post-login/$', 'mandayejs.mandaye.views.post_login', name='post-login'),
28 29
    url(r'^_mandaye/post-login-do/$', 'mandayejs.mandaye.views.post_login_do', name='post-login-do'),
29 30
    url(r'^_mandaye/admin/', include(admin.site.urls)),
31
    url(r'^_mandaye/ws/(?P<path>.*)$', app_web_services)
30 32
)
31 33

  
32 34
if 'mellon' in settings.INSTALLED_APPS:
33 35
    urlpatterns += patterns('', url(r'^_mandaye/accounts/mellon/', include('mellon.urls')))
34 36

  
35
if 'mandayejs.sites.archimed' in settings.INSTALLED_APPS:
36
    urlpatterns += patterns('',
37
        url(r'^_mandaye/archimed/', include('mandayejs.sites.archimed.urls')),
38
    )
39
-