diff options
author | tinytmy <tangmeiyan77@gmail.com> | 2015-04-01 09:31:41 +0800 |
---|---|---|
committer | David Lyle <dklyle0@gmail.com> | 2015-07-15 12:20:50 -0600 |
commit | ce7599006d9fc08fcfb456312d98847993f76026 (patch) | |
tree | 0d80ab53813dbfb9f2fa88f34e17771aad9eb2af | |
parent | cbdb7f3e70dc9cfe4c9ff67017de8ac010b232d4 (diff) | |
download | django_openstack_auth-ce7599006d9fc08fcfb456312d98847993f76026.tar.gz |
Add message show for switch project
When we switch the project admin to demo there
is no message show althrough success, we can add
message show.
Closes-bug:#1436709
Change-Id: Ie06c2c955939f73d89583e40f03cca6428695a6e
-rw-r--r-- | openstack_auth/tests/settings.py | 4 | ||||
-rw-r--r-- | openstack_auth/views.py | 13 |
2 files changed, 13 insertions, 4 deletions
diff --git a/openstack_auth/tests/settings.py b/openstack_auth/tests/settings.py index 44ee1ff..753a02a 100644 --- a/openstack_auth/tests/settings.py +++ b/openstack_auth/tests/settings.py @@ -20,6 +20,7 @@ INSTALLED_APPS = [ 'django.contrib.contenttypes', 'django.contrib.auth', 'django.contrib.sessions', + 'django.contrib.messages', 'openstack_auth', 'openstack_auth.tests' ] @@ -28,7 +29,8 @@ MIDDLEWARE_CLASSES = [ 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware' + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware' ] AUTHENTICATION_BACKENDS = ['openstack_auth.backend.KeystoneBackend'] diff --git a/openstack_auth/views.py b/openstack_auth/views.py index 469f4f5..a4f93fe 100644 --- a/openstack_auth/views.py +++ b/openstack_auth/views.py @@ -18,10 +18,12 @@ from django.conf import settings from django.contrib import auth from django.contrib.auth.decorators import login_required # noqa from django.contrib.auth import views as django_auth_views +from django.contrib import messages from django import http as django_http from django import shortcuts from django.utils import functional from django.utils import http +from django.utils.translation import ugettext_lazy as _ from django.views.decorators.cache import never_cache # noqa from django.views.decorators.csrf import csrf_exempt # noqa from django.views.decorators.csrf import csrf_protect # noqa @@ -217,9 +219,10 @@ def switch(request, tenant_id, redirect_field_name=auth.REDIRECT_FIELD_NAME): {'username': request.user.username} LOG.info(msg) except keystone_exceptions.ClientException: - msg = 'Project switch failed for user "%(username)s".' % \ - {'username': request.user.username} - LOG.warning(msg) + msg = ( + _('Project switch failed for user "%(username)s".') % + {'username': request.user.username}) + messages.error(request, msg) auth_ref = None LOG.exception('An error occurred while switching sessions.') @@ -239,6 +242,10 @@ def switch(request, tenant_id, redirect_field_name=auth.REDIRECT_FIELD_NAME): auth_user.Token(auth_ref, unscoped_token=unscoped_token), endpoint) auth_user.set_session_from_user(request, user) + message = ( + _('Switch to project "%(project_name)s" successful.') % + {'project_name': request.user.project_name}) + messages.success(request, message) response = shortcuts.redirect(redirect_to) utils.set_response_cookie(response, 'recent_project', request.user.project_id) |