Add unique_id()
validator method to Customer view
This commit is contained in:
parent
e916d4f71f
commit
6a57e51f6b
|
@ -243,6 +243,15 @@ class CustomersView(MasterView):
|
|||
f.set_renderer('groups', self.render_groups)
|
||||
f.set_readonly('groups')
|
||||
|
||||
def unique_id(self, node, value):
|
||||
query = self.Session.query(model.Customer)\
|
||||
.filter(model.Customer.id == value)
|
||||
if self.editing:
|
||||
customer = self.get_instance()
|
||||
query = query.filter(model.Customer.uuid != customer.uuid)
|
||||
if query.count():
|
||||
raise colander.Invalid(node, "Customer ID must be unique")
|
||||
|
||||
def objectify(self, form, data=None):
|
||||
if data is None:
|
||||
data = form.validated
|
||||
|
@ -385,6 +394,7 @@ class CustomersView(MasterView):
|
|||
|
||||
|
||||
# TODO: this only works when creating, need to add edit support?
|
||||
# TODO: can this just go away? since we have unique_id() view method above
|
||||
def unique_id(node, value):
|
||||
customers = Session.query(model.Customer).filter(model.Customer.id == value)
|
||||
if customers.count():
|
||||
|
|
Loading…
Reference in a new issue