#NEWLINE# def update( self , node , validated_data ) : #NEWLINE# #INDENT# 'Update instance with the validated data. Requires\n        the request to be in the serializer context.\n        ' #NEWLINE# assert isinstance ( node , Node ) , 'node must be a Node' #NEWLINE# auth = get_user_auth ( self . context [ 'request' ] ) #NEWLINE# old_tags = set ( [ tag . _id for tag in node . tags ] ) #NEWLINE# if ( 'tags' in validated_data ) : #NEWLINE# #INDENT# current_tags = set ( validated_data . get ( 'tags' ) ) #NEWLINE# del validated_data [ 'tags' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if self . partial : #NEWLINE# #INDENT# current_tags = set ( old_tags ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# current_tags = set ( ) #NEWLINE# #UNINDENT# #UNINDENT# for new_tag in ( current_tags - old_tags ) : #NEWLINE# #INDENT# node . add_tag ( new_tag , auth = auth ) #NEWLINE# #UNINDENT# for deleted_tag in ( old_tags - current_tags ) : #NEWLINE# #INDENT# node . remove_tag ( deleted_tag , auth = auth ) #NEWLINE# #UNINDENT# if validated_data : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# node . update ( validated_data , auth = auth ) #NEWLINE# #UNINDENT# except ValidationValueError as e : #NEWLINE# #INDENT# raise InvalidModelValueError ( detail = e . message ) #NEWLINE# #UNINDENT# except PermissionsError : #NEWLINE# #INDENT# raise exceptions . PermissionDenied #NEWLINE# #UNINDENT# except NodeUpdateError as e : #NEWLINE# #INDENT# raise exceptions . ValidationError ( detail = e . reason ) #NEWLINE# #UNINDENT# except NodeStateError as e : #NEWLINE# #INDENT# raise InvalidModelValueError ( detail = deleted_tag . message ) #NEWLINE# #UNINDENT# #UNINDENT# return node