flash: use consistent use of h.flash across the application.
This commit is contained in:
parent
1fe7ce51d6
commit
79f00ec46a
5 changed files with 24 additions and 31 deletions
|
|
@ -30,6 +30,7 @@ from rhodecode.lib.auth import (
|
|||
from rhodecode.lib.utils2 import safe_int
|
||||
from rhodecode.lib import system_info
|
||||
from rhodecode.lib import user_sessions
|
||||
from rhodecode.lib import helpers as h
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
@ -88,14 +89,12 @@ class AdminSessionSettingsView(BaseAppView):
|
|||
try:
|
||||
session_model.clean_sessions(
|
||||
older_than_seconds=older_than_seconds)
|
||||
self.request.session.flash(
|
||||
_('Cleaned up old sessions'), queue='success')
|
||||
h.flash(_('Cleaned up old sessions'), category='success')
|
||||
except user_sessions.CleanupCommand as msg:
|
||||
self.request.session.flash(msg.message, queue='warning')
|
||||
h.flash(msg.message, category='warning')
|
||||
except Exception as e:
|
||||
log.exception('Failed session cleanup')
|
||||
self.request.session.flash(
|
||||
_('Failed to cleanup up old sessions'), queue='error')
|
||||
h.flash(_('Failed to cleanup up old sessions'), category='error')
|
||||
|
||||
redirect_to = self.request.resource_path(
|
||||
self.context, route_name='admin_settings_sessions')
|
||||
|
|
|
|||
|
|
@ -166,8 +166,7 @@ class AdminSystemInfoSettingsView(BaseAppView):
|
|||
c.data_items.pop(0) # remove server info
|
||||
self.request.override_renderer = 'admin/settings/settings_system_snapshot.mako'
|
||||
else:
|
||||
self.request.session.flash(
|
||||
'You are not allowed to do this', queue='warning')
|
||||
h.flash('You are not allowed to do this', category='warning')
|
||||
return self._get_template_context(c)
|
||||
|
||||
@LoginRequired()
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
import pytest
|
||||
|
||||
|
||||
class EnabledAuthPlugin():
|
||||
class EnabledAuthPlugin(object):
|
||||
"""
|
||||
Context manager that updates the 'auth_plugins' setting in DB to enable
|
||||
a plugin. Previous setting is restored on exit. The rhodecode auth plugin
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ from pyramid.response import Response
|
|||
from rhodecode.apps._base import BaseAppView
|
||||
from rhodecode.authentication.base import (
|
||||
get_auth_cache_manager, get_perms_cache_manager, get_authn_registry)
|
||||
from rhodecode.lib import helpers as h
|
||||
from rhodecode.lib.auth import (
|
||||
LoginRequired, HasPermissionAllDecorator, CSRFRequired)
|
||||
from rhodecode.model.forms import AuthSettingsForm
|
||||
|
|
@ -88,10 +89,10 @@ class AuthnPluginViewBase(BaseAppView):
|
|||
valid_data = schema.deserialize(data)
|
||||
except colander.Invalid as e:
|
||||
# Display error message and display form again.
|
||||
self.request.session.flash(
|
||||
h.flash(
|
||||
_('Errors exist when saving plugin settings. '
|
||||
'Please check the form inputs.'),
|
||||
queue='error')
|
||||
category='error')
|
||||
defaults = {key: data[key] for key in data if key in schema}
|
||||
return self.settings_get(errors=e.asdict(), defaults=defaults)
|
||||
|
||||
|
|
@ -101,9 +102,7 @@ class AuthnPluginViewBase(BaseAppView):
|
|||
Session().commit()
|
||||
|
||||
# Display success message and redirect.
|
||||
self.request.session.flash(
|
||||
_('Auth settings updated successfully.'),
|
||||
queue='success')
|
||||
h.flash(_('Auth settings updated successfully.'), category='success')
|
||||
redirect_to = self.request.resource_path(
|
||||
self.context, route_name='auth_home')
|
||||
return HTTPFound(redirect_to)
|
||||
|
|
@ -168,24 +167,19 @@ class AuthSettingsView(BaseAppView):
|
|||
cache_manager = get_perms_cache_manager()
|
||||
cache_manager.clear()
|
||||
|
||||
self.request.session.flash(
|
||||
_('Auth settings updated successfully.'),
|
||||
queue='success')
|
||||
h.flash(_('Auth settings updated successfully.'), category='success')
|
||||
except formencode.Invalid as errors:
|
||||
e = errors.error_dict or {}
|
||||
self.request.session.flash(
|
||||
_('Errors exist when saving plugin setting. '
|
||||
'Please check the form inputs.'),
|
||||
queue='error')
|
||||
h.flash(_('Errors exist when saving plugin setting. '
|
||||
'Please check the form inputs.'), category='error')
|
||||
return self.index(
|
||||
defaults=errors.value,
|
||||
errors=e,
|
||||
prefix_error=False)
|
||||
except Exception:
|
||||
log.exception('Exception in auth_settings')
|
||||
self.request.session.flash(
|
||||
_('Error occurred during update of auth settings.'),
|
||||
queue='error')
|
||||
h.flash(_('Error occurred during update of auth settings.'),
|
||||
category='error')
|
||||
|
||||
redirect_to = self.request.resource_path(
|
||||
self.context, route_name='auth_home')
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ from rhodecode.lib.auth import (
|
|||
LoginRequired, CSRFRequired, HasPermissionAnyDecorator,
|
||||
HasRepoPermissionAnyDecorator, HasRepoGroupPermissionAnyDecorator)
|
||||
from rhodecode.lib.utils2 import safe_int
|
||||
from rhodecode.lib.helpers import Page
|
||||
from rhodecode.lib import helpers as h
|
||||
from rhodecode.model.db import Repository, RepoGroup, Session, Integration
|
||||
from rhodecode.model.scm import ScmModel
|
||||
from rhodecode.model.integration import IntegrationModel
|
||||
|
|
@ -169,10 +169,10 @@ class IntegrationSettingsViewBase(BaseAppView):
|
|||
_ = self.request.translate
|
||||
Session().delete(integration)
|
||||
Session().commit()
|
||||
self.request.session.flash(
|
||||
h.flash(
|
||||
_('Integration {integration_name} deleted successfully.').format(
|
||||
integration_name=integration.name),
|
||||
queue='success')
|
||||
category='success')
|
||||
|
||||
if self.repo:
|
||||
redirect_to = self.request.route_path(
|
||||
|
|
@ -208,6 +208,7 @@ class IntegrationSettingsViewBase(BaseAppView):
|
|||
integrations.append((IntType, integration))
|
||||
|
||||
sort_arg = self.request.GET.get('sort', 'name:asc')
|
||||
sort_dir = 'asc'
|
||||
if ':' in sort_arg:
|
||||
sort_field, sort_dir = sort_arg.split(':')
|
||||
else:
|
||||
|
|
@ -223,7 +224,7 @@ class IntegrationSettingsViewBase(BaseAppView):
|
|||
self.request.path, self.request.GET)
|
||||
page = safe_int(self.request.GET.get('page', 1), 1)
|
||||
|
||||
integrations = Page(
|
||||
integrations = h.Page(
|
||||
integrations, page=page, items_per_page=10, url=page_url)
|
||||
|
||||
c.rev_sort_dir = sort_dir != 'desc' and 'desc' or 'asc'
|
||||
|
|
@ -297,10 +298,10 @@ class IntegrationSettingsViewBase(BaseAppView):
|
|||
try:
|
||||
valid_data = form.validate_pstruct(pstruct)
|
||||
except deform.ValidationFailure as e:
|
||||
self.request.session.flash(
|
||||
h.flash(
|
||||
_('Errors exist when saving integration settings. '
|
||||
'Please check the form inputs.'),
|
||||
queue='error')
|
||||
category='error')
|
||||
return self._settings_get(form=e)
|
||||
|
||||
if not self.integration:
|
||||
|
|
@ -322,10 +323,10 @@ class IntegrationSettingsViewBase(BaseAppView):
|
|||
self.integration.settings = valid_data['settings']
|
||||
Session().commit()
|
||||
# Display success message and redirect.
|
||||
self.request.session.flash(
|
||||
h.flash(
|
||||
_('Integration {integration_name} updated successfully.').format(
|
||||
integration_name=self.IntegrationType.display_name),
|
||||
queue='success')
|
||||
category='success')
|
||||
|
||||
# if integration scope changes, we must redirect to the right place
|
||||
# keeping in mind if the original view was for /repo/ or /_admin/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue