Merge pull request #69 from lovvvve/patch-1

CiManager.add and AttributeValueManager.create_or_update_attr_value update
This commit is contained in:
pycook 2021-01-28 17:09:01 +08:00 committed by GitHub
commit 5256f79ba1
2 changed files with 10 additions and 5 deletions

View File

@ -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:

View File

@ -160,7 +160,8 @@ 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:
if value != 0 and not value and attr.value_type != ValueTypeEnum.TEXT:
existed_attr.delete() existed_attr.delete()
else: else:
existed_attr.update(value=value) existed_attr.update(value=value)