本文整理汇总了Python中concepts.models.ConceptVersion.diff方法的典型用法代码示例。如果您正苦于以下问题:Python ConceptVersion.diff方法的具体用法?Python ConceptVersion.diff怎么用?Python ConceptVersion.diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类concepts.models.ConceptVersion
的用法示例。
在下文中一共展示了ConceptVersion.diff方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_concept_version
# 需要导入模块: from concepts.models import ConceptVersion [as 别名]
# 或者: from concepts.models.ConceptVersion import diff [as 别名]
def update_concept_version(self, concept_version, data):
""" Updates the concept, or skips if no diff. Ignores retired status. """
# Generate the diff
clone = concept_version.clone()
serializer = ConceptVersionUpdateSerializer(
clone, data=data, context={'request': MockRequest(self.user)})
if not serializer.is_valid():
raise IllegalInputException(
'Could not parse concept to update: %s.' % concept_version.mnemonic)
new_version = serializer.object
diffs = ConceptVersion.diff(concept_version, new_version)
# Update concept if different
if diffs:
if 'names' in diffs:
diffs['names'] = {'is': data.get('names')}
if 'descriptions' in diffs:
diffs['descriptions'] = {'is': data.get('descriptions')}
clone.update_comment = json.dumps(diffs)
if not self.test_mode:
serializer.save()
if not serializer.is_valid():
raise IllegalInputException(
'Could not persist update to concept: %s' % concept_version.mnemonic)
return ImportActionHelper.IMPORT_ACTION_UPDATE
# No diff, so do nothing
return ImportActionHelper.IMPORT_ACTION_NONE