##// END OF EJS Templates
authn: Fix handling of form errors and default values.
johbo -
r90:1b568d51 default
parent child Browse files
Show More
@@ -45,19 +45,21 b' class AuthnPluginViewBase(object):'
45 self.context = context
45 self.context = context
46 self.plugin = context.plugin
46 self.plugin = context.plugin
47
47
48 def settings_get(self, errors={}):
48 def settings_get(self, defaults=None, errors=None):
49 """
49 """
50 View that displays the plugin settings as a form.
50 View that displays the plugin settings as a form.
51 """
51 """
52 defaults = defaults or {}
53 errors = errors or {}
52 schema = self.plugin.get_settings_schema()
54 schema = self.plugin.get_settings_schema()
53
55
54 # Get default values for the form.
56 # Get default values for the form.
55 for node in schema.children:
57 for node in schema:
56 value = self.plugin.get_setting_by_name(node.name)
58 db_value = self.plugin.get_setting_by_name(node.name)
57 if value:
59 defaults.setdefault(node.name, db_value)
58 node.default = value
59
60
60 template_context = {
61 template_context = {
62 'defaults': defaults,
61 'errors': errors,
63 'errors': errors,
62 'plugin': self.context.plugin,
64 'plugin': self.context.plugin,
63 'resource': self.context,
65 'resource': self.context,
@@ -78,7 +80,8 b' class AuthnPluginViewBase(object):'
78 _('Errors exist when saving plugin settings. '
80 _('Errors exist when saving plugin settings. '
79 'Please check the form inputs.'),
81 'Please check the form inputs.'),
80 queue='error')
82 queue='error')
81 return self.settings_get(errors=e.asdict())
83 defaults = schema.flatten(self.request.params)
84 return self.settings_get(errors=e.asdict(), defaults=defaults)
82
85
83 # Store validated data.
86 # Store validated data.
84 for name, value in valid_data.items():
87 for name, value in valid_data.items():
@@ -110,7 +113,8 b' class AuthSettingsView(object):'
110
113
111 @LoginRequired()
114 @LoginRequired()
112 @HasPermissionAllDecorator('hg.admin')
115 @HasPermissionAllDecorator('hg.admin')
113 def index(self, defaults={}, errors=None, prefix_error=False):
116 def index(self, defaults=None, errors=None, prefix_error=False):
117 defaults = defaults or {}
114 authn_registry = self.request.registry.getUtility(IAuthnPluginRegistry)
118 authn_registry = self.request.registry.getUtility(IAuthnPluginRegistry)
115 enabled_plugins = SettingsModel().get_auth_plugins()
119 enabled_plugins = SettingsModel().get_auth_plugins()
116
120
@@ -56,13 +56,13 b''
56 <div class="label ${label_css_class}"><label for="${node.name}">${node.title}</label></div>
56 <div class="label ${label_css_class}"><label for="${node.name}">${node.title}</label></div>
57 <div class="input">
57 <div class="input">
58 %if node.widget in ["string", "int", "unicode"]:
58 %if node.widget in ["string", "int", "unicode"]:
59 ${h.text(node.name, node.default, class_="medium")}
59 ${h.text(node.name, defaults.get(node.name), class_="medium")}
60 %elif node.widget == "password":
60 %elif node.widget == "password":
61 ${h.password(node.name, node.default, class_="medium")}
61 ${h.password(node.name, defaults.get(node.name), class_="medium")}
62 %elif node.widget == "bool":
62 %elif node.widget == "bool":
63 <div class="checkbox">${h.checkbox(node.name, node.default)}</div>
63 <div class="checkbox">${h.checkbox(node.name, True, checked=defaults.get(node.name))}</div>
64 %elif node.widget == "select":
64 %elif node.widget == "select":
65 ${h.select(node.name, node.default, node.validator.choices)}
65 ${h.select(node.name, defaults.get(node.name), node.validator.choices)}
66 %elif node.widget == "readonly":
66 %elif node.widget == "readonly":
67 ${node.default}
67 ${node.default}
68 %else:
68 %else:
General Comments 0
You need to be logged in to leave comments. Login now