Add validation for unique name when creating new Setting
This commit is contained in:
parent
242bcd7603
commit
5cb3f15616
|
@ -30,9 +30,18 @@ import re
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
|
||||||
|
import formalchemy as fa
|
||||||
|
|
||||||
|
from tailbone.db import Session
|
||||||
from tailbone.views import MasterView
|
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):
|
class SettingsView(MasterView):
|
||||||
"""
|
"""
|
||||||
Master view for the settings model.
|
Master view for the settings model.
|
||||||
|
@ -51,15 +60,17 @@ class SettingsView(MasterView):
|
||||||
],
|
],
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
def _preconfigure_fieldset(self, fs):
|
||||||
fs.configure(
|
fs.name.set(validate=unique_name)
|
||||||
include=[
|
|
||||||
fs.name,
|
|
||||||
fs.value,
|
|
||||||
])
|
|
||||||
if self.editing:
|
if self.editing:
|
||||||
fs.name.set(readonly=True)
|
fs.name.set(readonly=True)
|
||||||
|
|
||||||
|
def configure_fieldset(self, fs):
|
||||||
|
fs.configure(include=[
|
||||||
|
fs.name,
|
||||||
|
fs.value,
|
||||||
|
])
|
||||||
|
|
||||||
def editable_instance(self, setting):
|
def editable_instance(self, setting):
|
||||||
if self.rattail_config.demo():
|
if self.rattail_config.demo():
|
||||||
return not bool(self.feedback.match(setting.name))
|
return not bool(self.feedback.match(setting.name))
|
||||||
|
|
Loading…
Reference in a new issue