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,14 +60,16 @@ class SettingsView(MasterView):
|
||||||
],
|
],
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
|
||||||
|
def _preconfigure_fieldset(self, fs):
|
||||||
|
fs.name.set(validate=unique_name)
|
||||||
|
if self.editing:
|
||||||
|
fs.name.set(readonly=True)
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
def configure_fieldset(self, fs):
|
||||||
fs.configure(
|
fs.configure(include=[
|
||||||
include=[
|
|
||||||
fs.name,
|
fs.name,
|
||||||
fs.value,
|
fs.value,
|
||||||
])
|
])
|
||||||
if self.editing:
|
|
||||||
fs.name.set(readonly=True)
|
|
||||||
|
|
||||||
def editable_instance(self, setting):
|
def editable_instance(self, setting):
|
||||||
if self.rattail_config.demo():
|
if self.rattail_config.demo():
|
||||||
|
|
Loading…
Reference in a new issue