#NEWLINE# def update( self , pk ) : #NEWLINE# #INDENT# document = self . _get_document ( pk ) #NEWLINE# data = self . validator . parse_post ( [ ] , [ 'content' , 'identifier' , 'index' , 'indexes' , 'metadata' ] ) #NEWLINE# save_document = False #NEWLINE# if data . get ( 'content' ) : #NEWLINE# #INDENT# document . content = data [ 'content' ] #NEWLINE# save_document = True #NEWLINE# #UNINDENT# if data . get ( 'identifier' ) : #NEWLINE# #INDENT# document . identifier = data [ 'identifier' ] #NEWLINE# save_document = True #NEWLINE# #UNINDENT# if save_document : #NEWLINE# #INDENT# document . save ( ) #NEWLINE# #UNINDENT# if ( 'metadata' in data ) : #NEWLINE# #INDENT# del document . metadata #NEWLINE# if data [ 'metadata' ] : #NEWLINE# #INDENT# document . metadata = data [ 'metadata' ] #NEWLINE# #UNINDENT# #UNINDENT# if len ( request . files ) : #NEWLINE# #INDENT# self . attach_files ( document ) #NEWLINE# #UNINDENT# indexes = self . validator . validate_indexes ( data , required = False ) #NEWLINE# if ( indexes is not None ) : #NEWLINE# #INDENT# with database . atomic ( ) : #NEWLINE# #INDENT# IndexDocument . delete ( ) . where ( ( IndexDocument . document == document ) ) . execute ( ) #NEWLINE# if indexes : #NEWLINE# #INDENT# IndexDocument . insert_many ( [ { #NEWLINE# #INDENT# 'index' : index , #NEWLINE# 'document' : document , #NEWLINE# #UNINDENT# } for index in indexes ] ) . execute ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return self . detail ( document . get_id ( ) )