class ConceptVersionUpdateSerializer(serializers.Serializer): external_id = serializers.CharField(required=False) concept_class = serializers.CharField(required=False) datatype = serializers.CharField(required=False) names = LocalizedTextListField(required=False) descriptions = LocalizedTextListField(required=False, name_override='description') retired = serializers.BooleanField(required=False) extras = serializers.WritableField(required=False) update_comment = serializers.CharField(required=False) class Meta: model = ConceptVersion def restore_object(self, attrs, instance=None): instance.concept_class = attrs.get('concept_class', instance.concept_class) instance.datatype = attrs.get('datatype', instance.datatype) instance.extras = attrs.get('extras', instance.extras) instance.external_id = attrs.get('external_id', instance.external_id) instance.update_comment = attrs.get('update_comment') # Is this desired behavior?? instance.names = attrs.get('names', instance.names) # Is this desired behavior?? instance.descriptions = attrs.get('descriptions', instance.descriptions) instance.retired = attrs.get('retired', instance.retired) return instance def save_object(self, obj, **kwargs): user = self.context['request'].user errors = ConceptVersion.persist_clone(obj, user, **kwargs) self._errors.update(errors)
class ConceptDetailSerializer(serializers.Serializer): id = serializers.CharField( required=True, validators=[RegexValidator(regex=NAMESPACE_REGEX)], source='mnemonic') external_id = serializers.CharField(required=False) concept_class = serializers.CharField(required=False) datatype = serializers.CharField(required=False) display_name = serializers.CharField(read_only=True) display_locale = serializers.CharField(read_only=True) names = LocalizedTextListField(required=False) descriptions = LocalizedTextListField(required=False, name_override='description') retired = serializers.BooleanField(required=False) url = serializers.URLField(read_only=True) source = serializers.CharField(source='parent_resource', read_only=True) owner = serializers.CharField(source='owner_name', read_only=True) owner_type = serializers.CharField(read_only=True) owner_url = serializers.URLField(read_only=True) created_on = serializers.DateTimeField(source='created_at', read_only=True) updated_on = serializers.DateTimeField(source='updated_at', read_only=True) extras = serializers.WritableField(required=False) version = serializers.CharField(required=False) forked_concept_version = serializers.CharField(required=False) forked_from_url = serializers.CharField(required=False) class Meta: model = Concept lookup_field = 'mnemonic' def restore_object(self, attrs, instance=None): print 'ConceptDetailSerializer attrs: ', attrs concept = instance if instance else Concept() concept.mnemonic = attrs.get(self.Meta.lookup_field, concept.mnemonic) concept.external_id = attrs.get('external_id', concept.external_id) concept.concept_class = attrs.get('concept_class', concept.concept_class) concept.datatype = attrs.get('datatype', concept.datatype) concept.extras = attrs.get('extras', concept.extras) concept.retired = attrs.get('retired', concept.retired) concept.forked_from_url = attrs.get('forked_from_url', concept.forked_from_url) concept.forked_concept_version = attrs.get('version', concept.version) # Is this desired behavior?? concept.names = attrs.get('names', concept.names) # Is this desired behavior?? concept.descriptions = attrs.get('descriptions', concept.descriptions) concept.extras = attrs.get('extras', concept.extras) return concept def save_object(self, obj, **kwargs): request_user = self.context['request'].user errors = Concept.persist_new(obj, request_user, **kwargs) self._errors.update(errors)
class ConceptVersionDetailSerializer(ResourceVersionSerializer): type = serializers.CharField(source='versioned_resource_type') uuid = serializers.CharField(source='id') id = serializers.CharField(source='name') external_id = serializers.CharField() concept_class = serializers.CharField() datatype = serializers.CharField() display_name = serializers.CharField() display_locale = serializers.CharField() names = LocalizedTextListField() descriptions = LocalizedTextListField(name_override='description') extras = serializers.WritableField() retired = serializers.BooleanField() source = serializers.CharField(source='parent_resource') source_url = serializers.URLField(source='parent_url') owner = serializers.CharField(source='owner_name') owner_type = serializers.CharField() owner_url = serializers.URLField() version = serializers.CharField(source='mnemonic') created_on = serializers.DateTimeField(source='created_at', read_only=True) updated_on = serializers.DateTimeField(source='updated_at', read_only=True) version_created_on = serializers.DateTimeField(source='created_at') version_created_by = serializers.CharField() extras = serializers.WritableField() mappings = MappingListField(read_only=True) is_latest_version = serializers.CharField() locale = serializers.SerializerMethodField(method_name='get_locale') forked_from_url = serializers.CharField() forked_concept_version = serializers.CharField() class Meta: model = ConceptVersion versioned_object_field_name = 'url' versioned_object_view_name = 'concept-detail' def __init__(self, *args, **kwargs): context = kwargs.get('context', {}) include_direct_mappings = context.get('include_direct_mappings', False) include_indirect_mappings = context.get('include_indirect_mappings', False) super(ConceptVersionDetailSerializer, self).__init__(*args, **kwargs) mappings_field = self.fields.get('mappings') if include_indirect_mappings: mappings_field.source = 'get_bidirectional_mappings' elif include_direct_mappings: mappings_field.source = 'get_unidirectional_mappings' else: mappings_field.source = 'get_empty_mappings'