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
This commit is contained in:
tinytmy
2015-04-01 09:31:41 +08:00
committed by David Lyle
parent cbdb7f3e70
commit ce7599006d
2 changed files with 13 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ INSTALLED_APPS = [
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages',
'openstack_auth', 'openstack_auth',
'openstack_auth.tests' 'openstack_auth.tests'
] ]
@@ -28,7 +29,8 @@ MIDDLEWARE_CLASSES = [
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', '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'] AUTHENTICATION_BACKENDS = ['openstack_auth.backend.KeystoneBackend']

View File

@@ -18,10 +18,12 @@ from django.conf import settings
from django.contrib import auth from django.contrib import auth
from django.contrib.auth.decorators import login_required # noqa from django.contrib.auth.decorators import login_required # noqa
from django.contrib.auth import views as django_auth_views 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 http as django_http
from django import shortcuts from django import shortcuts
from django.utils import functional from django.utils import functional
from django.utils import http 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.cache import never_cache # noqa
from django.views.decorators.csrf import csrf_exempt # noqa from django.views.decorators.csrf import csrf_exempt # noqa
from django.views.decorators.csrf import csrf_protect # 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} {'username': request.user.username}
LOG.info(msg) LOG.info(msg)
except keystone_exceptions.ClientException: except keystone_exceptions.ClientException:
msg = 'Project switch failed for user "%(username)s".' % \ msg = (
{'username': request.user.username} _('Project switch failed for user "%(username)s".') %
LOG.warning(msg) {'username': request.user.username})
messages.error(request, msg)
auth_ref = None auth_ref = None
LOG.exception('An error occurred while switching sessions.') 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), auth_user.Token(auth_ref, unscoped_token=unscoped_token),
endpoint) endpoint)
auth_user.set_session_from_user(request, user) 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) response = shortcuts.redirect(redirect_to)
utils.set_response_cookie(response, 'recent_project', utils.set_response_cookie(response, 'recent_project',
request.user.project_id) request.user.project_id)