mirror of https://github.com/veops/cmdb.git
Merge pull request #69 from lovvvve/patch-1
CiManager.add and AttributeValueManager.create_or_update_attr_value update
This commit is contained in:
commit
5256f79ba1
|
@ -187,8 +187,12 @@ class CIManager(object):
|
||||||
return abort(404, 'CI <{0}> does not exist'.format(unique_value))
|
return abort(404, 'CI <{0}> does not exist'.format(unique_value))
|
||||||
ci = CI.create(type_id=ci_type.id)
|
ci = CI.create(type_id=ci_type.id)
|
||||||
|
|
||||||
|
ci_type_attrs_name = [attr["name"] for attr in CITypeAttributeManager().get_attributes_by_type_id(ci_type.id)]
|
||||||
value_manager = AttributeValueManager()
|
value_manager = AttributeValueManager()
|
||||||
for p, v in ci_dict.items():
|
for p, v in ci_dict.items():
|
||||||
|
if p not in ci_type_attrs_name:
|
||||||
|
current_app.logger.warning('ci_type: {0} not has attribute {1}, please check!'.format(ci_type_name, p))
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
value_manager.create_or_update_attr_value(p, v, ci, _no_attribute_policy)
|
value_manager.create_or_update_attr_value(p, v, ci, _no_attribute_policy)
|
||||||
except BadRequest as e:
|
except BadRequest as e:
|
||||||
|
|
|
@ -160,12 +160,13 @@ class AttributeValueManager(object):
|
||||||
|
|
||||||
self._write_change(ci.id, attr.id, OperateType.ADD, None, value)
|
self._write_change(ci.id, attr.id, OperateType.ADD, None, value)
|
||||||
else:
|
else:
|
||||||
if not value and attr.value_type != ValueTypeEnum.TEXT:
|
if existed_value != value:
|
||||||
existed_attr.delete()
|
if value != 0 and not value and attr.value_type != ValueTypeEnum.TEXT:
|
||||||
else:
|
existed_attr.delete()
|
||||||
existed_attr.update(value=value)
|
else:
|
||||||
|
existed_attr.update(value=value)
|
||||||
|
|
||||||
self._write_change(ci.id, attr.id, OperateType.UPDATE, existed_value, value)
|
self._write_change(ci.id, attr.id, OperateType.UPDATE, existed_value, value)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def delete_attr_value(attr_id, ci_id):
|
def delete_attr_value(attr_id, ci_id):
|
||||||
|
|
Loading…
Reference in New Issue