mirror of https://github.com/veops/cmdb.git
attribute alias must be unique
This commit is contained in:
parent
0a36330852
commit
7b96ac4638
|
@ -96,7 +96,8 @@ class AttributeManager(object):
|
||||||
name = kwargs.pop("name")
|
name = kwargs.pop("name")
|
||||||
alias = kwargs.pop("alias", "")
|
alias = kwargs.pop("alias", "")
|
||||||
alias = name if not alias else alias
|
alias = name if not alias else alias
|
||||||
Attribute.get_by(name=name, first=True) and abort(400, "attribute {0} is already existed".format(name))
|
Attribute.get_by(name=name, first=True) and abort(400, "attribute name <{0}> is already existed".format(name))
|
||||||
|
Attribute.get_by(alias=alias, first=True) and abort(400, "attribute alias <{0}> is already existed".format(name))
|
||||||
|
|
||||||
attr = Attribute.create(flush=True,
|
attr = Attribute.create(flush=True,
|
||||||
name=name,
|
name=name,
|
||||||
|
@ -121,6 +122,15 @@ class AttributeManager(object):
|
||||||
def update(self, _id, **kwargs):
|
def update(self, _id, **kwargs):
|
||||||
attr = Attribute.get_by_id(_id) or abort(404, "Attribute <{0}> does not exist".format(_id))
|
attr = Attribute.get_by_id(_id) or abort(404, "Attribute <{0}> does not exist".format(_id))
|
||||||
|
|
||||||
|
if kwargs.get("name"):
|
||||||
|
other = Attribute.get_by(name=kwargs['name'], first=True, to_dict=False)
|
||||||
|
if other and other.id != attr.id:
|
||||||
|
return abort(400, "Attribute name <{0}> cannot be duplicate!".format(kwargs['name']))
|
||||||
|
if kwargs.get("alias"):
|
||||||
|
other = Attribute.get_by(alias=kwargs['alias'], first=True, to_dict=False)
|
||||||
|
if other and other.id != attr.id:
|
||||||
|
return abort(400, "Attribute alias <{0}> cannot be duplicate!".format(kwargs['alias']))
|
||||||
|
|
||||||
choice_value = kwargs.pop("choice_value", False)
|
choice_value = kwargs.pop("choice_value", False)
|
||||||
is_choice = True if choice_value else False
|
is_choice = True if choice_value else False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue