##// END OF EJS Templates
flash: use consistent use of h.flash across the application.
marcink -
r2366:38c79c48 default
parent child Browse files
Show More
@@ -30,6 +30,7 b' from rhodecode.lib.auth import ('
30 from rhodecode.lib.utils2 import safe_int
30 from rhodecode.lib.utils2 import safe_int
31 from rhodecode.lib import system_info
31 from rhodecode.lib import system_info
32 from rhodecode.lib import user_sessions
32 from rhodecode.lib import user_sessions
33 from rhodecode.lib import helpers as h
33
34
34
35
35 log = logging.getLogger(__name__)
36 log = logging.getLogger(__name__)
@@ -88,14 +89,12 b' class AdminSessionSettingsView(BaseAppVi'
88 try:
89 try:
89 session_model.clean_sessions(
90 session_model.clean_sessions(
90 older_than_seconds=older_than_seconds)
91 older_than_seconds=older_than_seconds)
91 self.request.session.flash(
92 h.flash(_('Cleaned up old sessions'), category='success')
92 _('Cleaned up old sessions'), queue='success')
93 except user_sessions.CleanupCommand as msg:
93 except user_sessions.CleanupCommand as msg:
94 self.request.session.flash(msg.message, queue='warning')
94 h.flash(msg.message, category='warning')
95 except Exception as e:
95 except Exception as e:
96 log.exception('Failed session cleanup')
96 log.exception('Failed session cleanup')
97 self.request.session.flash(
97 h.flash(_('Failed to cleanup up old sessions'), category='error')
98 _('Failed to cleanup up old sessions'), queue='error')
99
98
100 redirect_to = self.request.resource_path(
99 redirect_to = self.request.resource_path(
101 self.context, route_name='admin_settings_sessions')
100 self.context, route_name='admin_settings_sessions')
@@ -166,8 +166,7 b' class AdminSystemInfoSettingsView(BaseAp'
166 c.data_items.pop(0) # remove server info
166 c.data_items.pop(0) # remove server info
167 self.request.override_renderer = 'admin/settings/settings_system_snapshot.mako'
167 self.request.override_renderer = 'admin/settings/settings_system_snapshot.mako'
168 else:
168 else:
169 self.request.session.flash(
169 h.flash('You are not allowed to do this', category='warning')
170 'You are not allowed to do this', queue='warning')
171 return self._get_template_context(c)
170 return self._get_template_context(c)
172
171
173 @LoginRequired()
172 @LoginRequired()
@@ -22,7 +22,7 b''
22 import pytest
22 import pytest
23
23
24
24
25 class EnabledAuthPlugin():
25 class EnabledAuthPlugin(object):
26 """
26 """
27 Context manager that updates the 'auth_plugins' setting in DB to enable
27 Context manager that updates the 'auth_plugins' setting in DB to enable
28 a plugin. Previous setting is restored on exit. The rhodecode auth plugin
28 a plugin. Previous setting is restored on exit. The rhodecode auth plugin
@@ -29,6 +29,7 b' from pyramid.response import Response'
29 from rhodecode.apps._base import BaseAppView
29 from rhodecode.apps._base import BaseAppView
30 from rhodecode.authentication.base import (
30 from rhodecode.authentication.base import (
31 get_auth_cache_manager, get_perms_cache_manager, get_authn_registry)
31 get_auth_cache_manager, get_perms_cache_manager, get_authn_registry)
32 from rhodecode.lib import helpers as h
32 from rhodecode.lib.auth import (
33 from rhodecode.lib.auth import (
33 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
34 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
34 from rhodecode.model.forms import AuthSettingsForm
35 from rhodecode.model.forms import AuthSettingsForm
@@ -88,10 +89,10 b' class AuthnPluginViewBase(BaseAppView):'
88 valid_data = schema.deserialize(data)
89 valid_data = schema.deserialize(data)
89 except colander.Invalid as e:
90 except colander.Invalid as e:
90 # Display error message and display form again.
91 # Display error message and display form again.
91 self.request.session.flash(
92 h.flash(
92 _('Errors exist when saving plugin settings. '
93 _('Errors exist when saving plugin settings. '
93 'Please check the form inputs.'),
94 'Please check the form inputs.'),
94 queue='error')
95 category='error')
95 defaults = {key: data[key] for key in data if key in schema}
96 defaults = {key: data[key] for key in data if key in schema}
96 return self.settings_get(errors=e.asdict(), defaults=defaults)
97 return self.settings_get(errors=e.asdict(), defaults=defaults)
97
98
@@ -101,9 +102,7 b' class AuthnPluginViewBase(BaseAppView):'
101 Session().commit()
102 Session().commit()
102
103
103 # Display success message and redirect.
104 # Display success message and redirect.
104 self.request.session.flash(
105 h.flash(_('Auth settings updated successfully.'), category='success')
105 _('Auth settings updated successfully.'),
106 queue='success')
107 redirect_to = self.request.resource_path(
106 redirect_to = self.request.resource_path(
108 self.context, route_name='auth_home')
107 self.context, route_name='auth_home')
109 return HTTPFound(redirect_to)
108 return HTTPFound(redirect_to)
@@ -168,24 +167,19 b' class AuthSettingsView(BaseAppView):'
168 cache_manager = get_perms_cache_manager()
167 cache_manager = get_perms_cache_manager()
169 cache_manager.clear()
168 cache_manager.clear()
170
169
171 self.request.session.flash(
170 h.flash(_('Auth settings updated successfully.'), category='success')
172 _('Auth settings updated successfully.'),
173 queue='success')
174 except formencode.Invalid as errors:
171 except formencode.Invalid as errors:
175 e = errors.error_dict or {}
172 e = errors.error_dict or {}
176 self.request.session.flash(
173 h.flash(_('Errors exist when saving plugin setting. '
177 _('Errors exist when saving plugin setting. '
174 'Please check the form inputs.'), category='error')
178 'Please check the form inputs.'),
179 queue='error')
180 return self.index(
175 return self.index(
181 defaults=errors.value,
176 defaults=errors.value,
182 errors=e,
177 errors=e,
183 prefix_error=False)
178 prefix_error=False)
184 except Exception:
179 except Exception:
185 log.exception('Exception in auth_settings')
180 log.exception('Exception in auth_settings')
186 self.request.session.flash(
181 h.flash(_('Error occurred during update of auth settings.'),
187 _('Error occurred during update of auth settings.'),
182 category='error')
188 queue='error')
189
183
190 redirect_to = self.request.resource_path(
184 redirect_to = self.request.resource_path(
191 self.context, route_name='auth_home')
185 self.context, route_name='auth_home')
@@ -32,7 +32,7 b' from rhodecode.lib.auth import ('
32 LoginRequired, CSRFRequired, HasPermissionAnyDecorator,
32 LoginRequired, CSRFRequired, HasPermissionAnyDecorator,
33 HasRepoPermissionAnyDecorator, HasRepoGroupPermissionAnyDecorator)
33 HasRepoPermissionAnyDecorator, HasRepoGroupPermissionAnyDecorator)
34 from rhodecode.lib.utils2 import safe_int
34 from rhodecode.lib.utils2 import safe_int
35 from rhodecode.lib.helpers import Page
35 from rhodecode.lib import helpers as h
36 from rhodecode.model.db import Repository, RepoGroup, Session, Integration
36 from rhodecode.model.db import Repository, RepoGroup, Session, Integration
37 from rhodecode.model.scm import ScmModel
37 from rhodecode.model.scm import ScmModel
38 from rhodecode.model.integration import IntegrationModel
38 from rhodecode.model.integration import IntegrationModel
@@ -169,10 +169,10 b' class IntegrationSettingsViewBase(BaseAp'
169 _ = self.request.translate
169 _ = self.request.translate
170 Session().delete(integration)
170 Session().delete(integration)
171 Session().commit()
171 Session().commit()
172 self.request.session.flash(
172 h.flash(
173 _('Integration {integration_name} deleted successfully.').format(
173 _('Integration {integration_name} deleted successfully.').format(
174 integration_name=integration.name),
174 integration_name=integration.name),
175 queue='success')
175 category='success')
176
176
177 if self.repo:
177 if self.repo:
178 redirect_to = self.request.route_path(
178 redirect_to = self.request.route_path(
@@ -208,6 +208,7 b' class IntegrationSettingsViewBase(BaseAp'
208 integrations.append((IntType, integration))
208 integrations.append((IntType, integration))
209
209
210 sort_arg = self.request.GET.get('sort', 'name:asc')
210 sort_arg = self.request.GET.get('sort', 'name:asc')
211 sort_dir = 'asc'
211 if ':' in sort_arg:
212 if ':' in sort_arg:
212 sort_field, sort_dir = sort_arg.split(':')
213 sort_field, sort_dir = sort_arg.split(':')
213 else:
214 else:
@@ -223,7 +224,7 b' class IntegrationSettingsViewBase(BaseAp'
223 self.request.path, self.request.GET)
224 self.request.path, self.request.GET)
224 page = safe_int(self.request.GET.get('page', 1), 1)
225 page = safe_int(self.request.GET.get('page', 1), 1)
225
226
226 integrations = Page(
227 integrations = h.Page(
227 integrations, page=page, items_per_page=10, url=page_url)
228 integrations, page=page, items_per_page=10, url=page_url)
228
229
229 c.rev_sort_dir = sort_dir != 'desc' and 'desc' or 'asc'
230 c.rev_sort_dir = sort_dir != 'desc' and 'desc' or 'asc'
@@ -297,10 +298,10 b' class IntegrationSettingsViewBase(BaseAp'
297 try:
298 try:
298 valid_data = form.validate_pstruct(pstruct)
299 valid_data = form.validate_pstruct(pstruct)
299 except deform.ValidationFailure as e:
300 except deform.ValidationFailure as e:
300 self.request.session.flash(
301 h.flash(
301 _('Errors exist when saving integration settings. '
302 _('Errors exist when saving integration settings. '
302 'Please check the form inputs.'),
303 'Please check the form inputs.'),
303 queue='error')
304 category='error')
304 return self._settings_get(form=e)
305 return self._settings_get(form=e)
305
306
306 if not self.integration:
307 if not self.integration:
@@ -322,10 +323,10 b' class IntegrationSettingsViewBase(BaseAp'
322 self.integration.settings = valid_data['settings']
323 self.integration.settings = valid_data['settings']
323 Session().commit()
324 Session().commit()
324 # Display success message and redirect.
325 # Display success message and redirect.
325 self.request.session.flash(
326 h.flash(
326 _('Integration {integration_name} updated successfully.').format(
327 _('Integration {integration_name} updated successfully.').format(
327 integration_name=self.IntegrationType.display_name),
328 integration_name=self.IntegrationType.display_name),
328 queue='success')
329 category='success')
329
330
330 # if integration scope changes, we must redirect to the right place
331 # if integration scope changes, we must redirect to the right place
331 # keeping in mind if the original view was for /repo/ or /_admin/
332 # keeping in mind if the original view was for /repo/ or /_admin/
General Comments 0
You need to be logged in to leave comments. Login now