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