def update(self, draft, validated_data): draft = super(DraftRegistrationDetailSerializer, self).update(draft, validated_data) user = self.context['request'].user auth = get_user_auth(self.context['request']) if 'tags' in validated_data: new_tags = set(validated_data.pop('tags', [])) draft.update_tags(new_tags, auth=auth) if 'license_type' in validated_data or 'license' in validated_data: license_details = get_license_details(draft, validated_data) validated_data['node_license'] = license_details if 'affiliated_institutions' in validated_data: institutions_list = validated_data.pop('affiliated_institutions') new_institutions = [{'_id': institution} for institution in institutions_list] update_institutions(draft, new_institutions, user) if 'subjects' in validated_data: subjects = validated_data.pop('subjects', None) self.update_subjects(draft, subjects, auth) try: draft.update(validated_data, auth=auth) except PermissionsError: raise exceptions.PermissionDenied except DraftRegistrationStateError as e: raise InvalidModelValueError(detail=str(e)) return draft
def update(self, registration, validated_data): user = self.context['request'].user auth = Auth(user) self.check_perms(registration, user, validated_data) validated_data.pop('_id', None) if 'tags' in validated_data: self.update_registration_tags(registration, validated_data, auth) if 'custom_citation' in validated_data: registration.update_custom_citation( validated_data.pop('custom_citation'), auth) if 'license_type' in validated_data or 'license' in validated_data: license_details = get_license_details(registration, validated_data) validated_data['node_license'] = license_details validated_data.pop('license_type', None) validated_data.pop('license', None) if 'affiliated_institutions' in validated_data: institutions_list = validated_data.pop('affiliated_institutions') new_institutions = [{ '_id': institution } for institution in institutions_list] update_institutions(registration, new_institutions, user) registration.save() if 'subjects' in validated_data: subjects = validated_data.pop('subjects', None) self.update_subjects(registration, subjects, auth) if 'withdrawal_justification' in validated_data or 'is_pending_retraction' in validated_data: self.retract_registration(registration, validated_data, user) if 'is_public' in validated_data: if validated_data.get('is_public') is False: raise exceptions.ValidationError( 'Registrations can only be turned from private to public.') if 'provider_specific_metadata' in validated_data: try: registration.update_provider_specific_metadata( validated_data.pop('provider_specific_metadata'), ) except ValueError as e: raise exceptions.ValidationError(str(e)) try: registration.update(validated_data, auth=auth) except ValidationError as e: raise InvalidModelValueError(detail=e.messages[0]) except NodeUpdateError as err: raise exceptions.ValidationError(err.reason) except NodeStateError as err: raise exceptions.ValidationError(str(err)) return registration
def update(self, registration, validated_data): user = self.context['request'].user auth = Auth(user) self.check_admin_perms(registration, user, validated_data) validated_data.pop('_id', None) if 'tags' in validated_data: self.update_registration_tags(registration, validated_data, auth) if 'custom_citation' in validated_data: registration.update_custom_citation(validated_data.pop('custom_citation'), auth) if 'license_type' in validated_data or 'license' in validated_data: license_details = get_license_details(registration, validated_data) validated_data['node_license'] = license_details validated_data.pop('license_type', None) validated_data.pop('license', None) if 'affiliated_institutions' in validated_data: institutions_list = validated_data.pop('affiliated_institutions') new_institutions = [{'_id': institution} for institution in institutions_list] update_institutions(registration, new_institutions, user) registration.save() if 'withdrawal_justification' in validated_data or 'is_pending_retraction' in validated_data: self.retract_registration(registration, validated_data, user) if 'is_public' in validated_data: if validated_data.get('is_public') is False: raise exceptions.ValidationError('Registrations can only be turned from private to public.') try: registration.update(validated_data, auth=auth) except ValidationError as e: raise InvalidModelValueError(detail=e.messages[0]) except NodeUpdateError as err: raise exceptions.ValidationError(err.reason) except NodeStateError as err: raise exceptions.ValidationError(str(err)) return registration