本文整理汇总了Python中website.models.DraftRegistration.create_from_node方法的典型用法代码示例。如果您正苦于以下问题:Python DraftRegistration.create_from_node方法的具体用法?Python DraftRegistration.create_from_node怎么用?Python DraftRegistration.create_from_node使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类website.models.DraftRegistration
的用法示例。
在下文中一共展示了DraftRegistration.create_from_node方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from website.models import DraftRegistration [as 别名]
# 或者: from website.models.DraftRegistration import create_from_node [as 别名]
def create(self, validated_data):
node = validated_data.pop('node')
initiator = validated_data.pop('initiator')
metadata = validated_data.pop('registration_metadata', None)
schema_id = validated_data.pop('registration_schema').get('_id')
schema = get_object_or_error(MetaSchema, schema_id)
if schema.schema_version != LATEST_SCHEMA_VERSION or schema.name not in ACTIVE_META_SCHEMAS:
raise exceptions.ValidationError('Registration supplement must be an active schema.')
draft = DraftRegistration.create_from_node(node=node, user=initiator, schema=schema)
reviewer = is_prereg_admin_not_project_admin(self.context['request'], draft)
if metadata:
try:
# Required fields are only required when creating the actual registration, not updating the draft.
draft.validate_metadata(metadata=metadata, reviewer=reviewer, required_fields=False)
except ValidationValueError as e:
raise exceptions.ValidationError(e.message)
draft.update_metadata(metadata)
draft.save()
return draft