From 16f00b02dfa48196deed98c2c16d15b5f3beddb3 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 10 Dec 2016 11:23:22 -0600 Subject: [PATCH] Validate for unique tempmon probe config key --- tailbone/views/tempmon/probes.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tailbone/views/tempmon/probes.py b/tailbone/views/tempmon/probes.py index aed366da..bf2ede82 100644 --- a/tailbone/views/tempmon/probes.py +++ b/tailbone/views/tempmon/probes.py @@ -28,10 +28,23 @@ from __future__ import unicode_literals, absolute_import from rattail_tempmon.db import model as tempmon +import formalchemy as fa + from tailbone import forms +from tailbone.db import TempmonSession 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): """ Master view for tempmon probes. @@ -63,6 +76,7 @@ class TempmonProbeView(MasterView): readonly=True) def _preconfigure_fieldset(self, fs): + fs.config_key.set(validate=unique_config_key) fs.client.set(label="TempMon Client", renderer=ClientFieldRenderer) 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))