Révision eb2e07ac
Ajouté par Josué Kouka il y a environ 6 ans
mandayejs/applications/__init__.py | ||
---|---|---|
37 | 37 |
|
38 | 38 |
def app_web_services(request, path): |
39 | 39 |
app = get_app_settings() |
40 |
if hasattr(app, 'urlpatterns'):
|
|
41 |
view, args, kwargs = resolve(request.path, urlconf=app) |
|
40 |
if hasattr(app, 'SITE_WEBSERVICES'):
|
|
41 |
view, args, kwargs = resolve(request.path, urlconf=app.SITE_WEBSERVICES)
|
|
42 | 42 |
return view(request, *args, **kwargs) |
43 | 43 |
raise Http404 |
44 | 44 |
|
... | ... | |
92 | 92 |
return slugify(type(self).__name__) |
93 | 93 |
|
94 | 94 |
|
95 |
class AppWebservice(object): |
|
96 |
'''- endpoints = [ |
|
97 |
{'foo': 'https://example.org/foo/'}, |
|
98 |
{'bar': 'https://example.org/bar/'}, |
|
99 |
] |
|
100 |
- urlpatterns = [ |
|
101 |
url('user/(?P<username>\w+)/$', views.myapp.user_details, name='user-details'), |
|
102 |
url('user/(?P<username>\w+/books/$)', views.myapp.user_books, name='user-books'), |
|
103 |
] |
|
104 |
''' |
|
105 |
|
|
106 |
def __init__(self, endpoints=None, urlpatterns=None): |
|
107 |
self.endpoints = endpoints |
|
108 |
self.urlpatterns = urlpatterns |
|
109 |
|
|
110 |
def get_endpoint(self, name): |
|
111 |
for endpoint in self.endpoints: |
|
112 |
if endpoint.get(name, None): |
|
113 |
return endpoint[name] |
|
114 |
return None |
|
115 |
|
|
116 |
|
|
95 | 117 |
# Test App Settings |
96 | 118 |
class Test(AppSettings): |
97 | 119 |
SITE_LOGIN_PATH = '/' |
... | ... | |
190 | 212 |
|
191 | 213 |
SITE_FORCE_REDIRECT_LOCATOR = '.connectBox' |
192 | 214 |
|
193 |
SITE_WS_ENDPOINT = {
|
|
194 |
'account_details': '/DEFAULT/Ermes/Services/ILSClient.svc/RetrieveAccount',
|
|
195 |
}
|
|
196 |
|
|
197 |
urlpatterns = [
|
|
198 |
url(
|
|
199 |
r'account/(?P<username>\w+)/$',
|
|
200 |
views.archimed_account_details,
|
|
201 |
name='archimed-account-details'),
|
|
202 |
]
|
|
215 |
SITE_WEBSERVICES = AppWebservice(
|
|
216 |
[
|
|
217 |
{'account_details': '/DEFAULT/Ermes/Services/ILSClient.svc/RetrieveAccount'},
|
|
218 |
{'login_url': '/DEFAULT/Ermes/Recherche/logon.svc/logon'} |
|
219 |
],
|
|
220 |
[
|
|
221 |
url(r'account/(?P<username>\w+)/$', views.archimed_account_details,
|
|
222 |
name='archimed-account-details')
|
|
223 |
]
|
|
224 |
)
|
|
203 | 225 |
|
204 | 226 |
SITE_LOGOUT_LOCATOR = '.account_logoff' |
205 | 227 |
|
mandayejs/applications/views.py | ||
---|---|---|
45 | 45 |
logger = logging.getLogger(__name__) |
46 | 46 |
app_settings = get_app_settings() |
47 | 47 |
ws_uri = request.build_absolute_uri( |
48 |
app_settings.SITE_WS_ENDPOINT['account_details'])
|
|
48 |
app_settings.SITE_WEBSERVICES.get_endpoint('account_details'))
|
|
49 | 49 |
|
50 | 50 |
# mellon truncates username to 30 characters |
51 | 51 |
# thus the passed username must be truncated to 30 characters |
... | ... | |
63 | 63 |
return Response('User %s is not associated' % username, status=status.HTTP_404_NOT_FOUND) |
64 | 64 |
|
65 | 65 |
login_url = request.build_absolute_uri( |
66 |
'/DEFAULT/Ermes/Recherche/logon.svc/logon')
|
|
66 |
app_settings.SITE_WEBSERVICES.get_endpoint('login_url'))
|
|
67 | 67 |
|
68 | 68 |
with requests.Session() as session: |
69 | 69 |
login_info = credentials.to_login_info(decrypt=True) |
Formats disponibles : Unified diff
improve application's webservices config (#22064)