diff --git a/tailbone/views/settings.py b/tailbone/views/settings.py index f971d6dc..a20bb7d3 100644 --- a/tailbone/views/settings.py +++ b/tailbone/views/settings.py @@ -30,9 +30,18 @@ import re from rattail.db import model +import formalchemy as fa + +from tailbone.db import Session from tailbone.views import MasterView +def unique_name(value, field): + setting = Session.query(model.Setting).get(value) + if setting: + raise fa.ValidationError("Setting name must be unique") + + class SettingsView(MasterView): """ Master view for the settings model. @@ -51,15 +60,17 @@ class SettingsView(MasterView): ], readonly=True) - def configure_fieldset(self, fs): - fs.configure( - include=[ - fs.name, - fs.value, - ]) + def _preconfigure_fieldset(self, fs): + fs.name.set(validate=unique_name) if self.editing: fs.name.set(readonly=True) + def configure_fieldset(self, fs): + fs.configure(include=[ + fs.name, + fs.value, + ]) + def editable_instance(self, setting): if self.rattail_config.demo(): return not bool(self.feedback.match(setting.name))