Validate for unique tempmon probe config key
This commit is contained in:
parent
8578a063f3
commit
16f00b02df
|
@ -28,10 +28,23 @@ from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
from rattail_tempmon.db import model as tempmon
|
from rattail_tempmon.db import model as tempmon
|
||||||
|
|
||||||
|
import formalchemy as fa
|
||||||
|
|
||||||
from tailbone import forms
|
from tailbone import forms
|
||||||
|
from tailbone.db import TempmonSession
|
||||||
from tailbone.views.tempmon import MasterView, ClientFieldRenderer
|
from tailbone.views.tempmon import MasterView, ClientFieldRenderer
|
||||||
|
|
||||||
|
|
||||||
|
def unique_config_key(value, field):
|
||||||
|
probe = field.parent.model
|
||||||
|
query = TempmonSession.query(tempmon.Probe)\
|
||||||
|
.filter(tempmon.Probe.config_key == value)
|
||||||
|
if probe.uuid:
|
||||||
|
query = query.filter(tempmon.Probe.uuid != probe.uuid)
|
||||||
|
if query.count():
|
||||||
|
raise fa.ValidationError("Config key must be unique")
|
||||||
|
|
||||||
|
|
||||||
class TempmonProbeView(MasterView):
|
class TempmonProbeView(MasterView):
|
||||||
"""
|
"""
|
||||||
Master view for tempmon probes.
|
Master view for tempmon probes.
|
||||||
|
@ -63,6 +76,7 @@ class TempmonProbeView(MasterView):
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
|
||||||
def _preconfigure_fieldset(self, fs):
|
def _preconfigure_fieldset(self, fs):
|
||||||
|
fs.config_key.set(validate=unique_config_key)
|
||||||
fs.client.set(label="TempMon Client", renderer=ClientFieldRenderer)
|
fs.client.set(label="TempMon Client", renderer=ClientFieldRenderer)
|
||||||
fs.appliance_type.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.TEMPMON_APPLIANCE_TYPE))
|
fs.appliance_type.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.TEMPMON_APPLIANCE_TYPE))
|
||||||
fs.status.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.TEMPMON_PROBE_STATUS))
|
fs.status.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.TEMPMON_PROBE_STATUS))
|
||||||
|
|
Loading…
Reference in a new issue