#NEWLINE# @ webapi_check_local_site #NEWLINE# @ webapi_login_required #NEWLINE# @ webapi_response_errors ( DOES_NOT_EXIST , INVALID_FORM_DATA , NOT_LOGGED_IN , PERMISSION_DENIED ) #NEWLINE# @ webapi_request_fields ( optional = { #NEWLINE# #INDENT# 'note' : { #NEWLINE# #INDENT# 'type' : six . text_type , #NEWLINE# 'description' : 'The note explaining the purpose of this token.' , #NEWLINE# #UNINDENT# } , #NEWLINE# 'policy' : { #NEWLINE# #INDENT# 'type' : six . text_type , #NEWLINE# 'description' : 'The token access policy, encoded as a JSON string.' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , allow_unknown = True ) #NEWLINE# def update( self , request , extra_fields = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , * args , **kwargs ) : #NEWLINE# #INDENT# 'Updates the information on an existing API token.\n\n        The note, policy, and extra data on the token may be updated.\n        ' #NEWLINE# try : #NEWLINE# #INDENT# token = self . get_object ( request , * self , ** kwargs ) #NEWLINE# #UNINDENT# except ObjectDoesNotExist : #NEWLINE# #INDENT# return DOES_NOT_EXIST #NEWLINE# #UNINDENT# if ( not self . has_access_permissions ( request , token , * args , ** kwargs ) ) : #NEWLINE# #INDENT# return self . get_no_access_error ( request ) #NEWLINE# #UNINDENT# if ( 'note' in kwargs ) : #NEWLINE# #INDENT# token . note = kwargs [ 'note' ] #NEWLINE# #UNINDENT# if ( 'policy' in kwargs ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# token . policy = self . _validate_policy ( kwargs [ 'policy' ] ) #NEWLINE# #UNINDENT# except ValidationError as e : #NEWLINE# #INDENT# return ( INVALID_FORM_DATA , { #NEWLINE# #INDENT# 'fields' : { #NEWLINE# #INDENT# 'policy' : e . message , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# if extra_fields : #NEWLINE# #INDENT# self . import_extra_data ( token , token . extra_data , extra_fields ) #NEWLINE# #UNINDENT# token . save ( ) #NEWLINE# return ( 200 , { #NEWLINE# #INDENT# self . item_result_key : token , #NEWLINE# #UNINDENT# } )