From b3407641fe4a8110eb4a2473617b8fffbb3176e1 Mon Sep 17 00:00:00 2001 From: Sebastian Henschel Date: Mon, 19 Jun 2017 10:08:55 +0200 Subject: [PATCH] Switched API call to get single user from email address to user id --- apimanager/users/templates/users/index.html | 2 +- apimanager/users/urls.py | 2 +- apimanager/users/views.py | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apimanager/users/templates/users/index.html b/apimanager/users/templates/users/index.html index 3ef4d461..b3cd90f7 100644 --- a/apimanager/users/templates/users/index.html +++ b/apimanager/users/templates/users/index.html @@ -39,7 +39,7 @@

Statistics

{% for user in users %} - {% url 'users-detail' user.email as url_users_detail %} + {% url 'users-detail' user.user_id as url_users_detail %} {{ user.user_id }} {{ user.username }} diff --git a/apimanager/users/urls.py b/apimanager/users/urls.py index 27a68fe0..518e27f2 100644 --- a/apimanager/users/urls.py +++ b/apimanager/users/urls.py @@ -11,7 +11,7 @@ url(r'^$', IndexView.as_view(), name='users-index'), - url(r'^(?P[\w\@\.\+-]+)$', + url(r'^user_id/(?P[\w\@\.\+-]+)$', DetailView.as_view(), name='users-detail'), url(r'^(?P[\w-]+)/entitlement/delete/(?P[\w-]+)$', diff --git a/apimanager/users/views.py b/apimanager/users/views.py index 875bcafb..78e7c720 100644 --- a/apimanager/users/views.py +++ b/apimanager/users/views.py @@ -106,11 +106,9 @@ def get_context_data(self, **kwargs): # The API needs a call 'get user by id'! user = {} try: - urlpath = '/users/{}'.format(self.kwargs['user_email']) - users = api.get(self.request, urlpath) - if len(users['users']) > 0: - user = users['users'][0] - context['form'].fields['user_id'].initial = user['user_id'] + urlpath = '/users/user_id/{}'.format(self.kwargs['user_id']) + user = api.get(self.request, urlpath) + context['form'].fields['user_id'].initial = user['user_id'] except APIError as err: messages.error(self.request, err)