class LegacyDatasetUpdateSerializer(CommonNestedModelSerializer):
"""Serializer for updating migrated dataset fields.
Behaves mostly like DatasetSerializer but has less validation and allows
direct modification of some fields that aren't exposed in the usual .
"""
actors = DatasetActorSerializer(required=False, many=True)
access_rights = AccessRightsModelSerializer(required=False, allow_null=True, many=False)
field_of_science = FieldOfScience.get_serializer_field(required=False, many=True)
infrastructure = ResearchInfra.get_serializer_field(required=False, many=True)
actors = DatasetActorSerializer(required=False, many=True)
remote_resources = RemoteResourceSerializer(many=True, required=False)
language = Language.get_serializer_field(required=False, many=True)
metadata_owner = MetadataProviderModelSerializer(required=True)
other_identifiers = OtherIdentifierModelSerializer(required=False, many=True)
theme = Theme.get_serializer_field(required=False, many=True)
spatial = SpatialModelSerializer(required=False, many=True)
temporal = TemporalModelSerializer(required=False, many=True)
relation = EntityRelationSerializer(required=False, many=True)
preservation = LegacyPreservationSerializer(required=False, many=False)
provenance = ProvenanceModelSerializer(required=False, many=True)
projects = ProjectModelSerializer(required=False, many=True)
allowed_actions = DatasetAllowedActionsSerializer(read_only=True, source="*")
created = serializers.DateTimeField(required=False, read_only=False)
modified = serializers.DateTimeField(required=False, read_only=False)
removed = serializers.DateTimeField(required=False, read_only=False, allow_null=True)
next_draft = LinkedDraftSerializer(read_only=True)
draft_of = LinkedDraftSerializer(read_only=True)
is_legacy = serializers.HiddenField(default=True)
api_version = serializers.IntegerField()
id = serializers.UUIDField()
permissions_id = serializers.UUIDField(required=False, allow_null=True)
no_put_default_fields = {
"permissions_id"
} # Keep existing permissions_id if one is not provided
class Meta:
model = Dataset
nonpublic_fields = [ # Additional fields that are not in the normal public serializer
"last_cumulative_addition",
"last_modified_by",
"cumulation_started",
"cumulation_ended",
"is_legacy",
"api_version",
"permissions_id",
]
fields = [
field
for field in DatasetSerializer.Meta.fields
if field
not in [
"pid_type", # field removed
"metadata_repository", # field is not writable
"dataset_versions", # field is not writable
"metrics", # field is not writable
"fileset", # assigned directly in LegacyDataset
"version", # field is not writable
]
] + nonpublic_fields
def create(self, validated_data):
validated_data["_saving_legacy"] = True
state = validated_data.pop("state", None) # Always initialize dataset as draft
instance: Dataset = super().create(validated_data=validated_data)
if state == Dataset.StateChoices.PUBLISHED:
instance.publish() # Relations have been assigned, try to publish
return instance
def update(self, instance, validated_data):
instance._saving_legacy = True
instance._updating = True
super().update(instance, validated_data)
instance._updating = False
instance._saving_legacy = False
return instance