def diff_document(resource_def, old_doc, new_doc):
 diff = {}
 fields = (list(resource_def['schema'].keys()) + [app.config['VERSION'], app.config['LATEST_VERSION'], resource_def['id_field'], app.config['LAST_UPDATED'], app.config['DATE_CREATED'], app.config['ETAG'], app.config['LINKS']])
 if (resource_def['soft_delete'] is True):
  fields.append(app.config['DELETED'])
 for field in fields:
  if ((field in new_doc) and ((field not in old_doc) or (new_doc[field] != old_doc[field]))):
   diff[field] = new_doc[field]
 for field in app.config['VERSION_DIFF_INCLUDE']:
  if (field in new_doc):
   diff[field] = new_doc[field]
 return diff

def diff_document ( resource_def , old_doc , new_doc ) : diff = { } fields = ( list ( resource_def [ 'schema' ] . keys ( ) ) + [ app . config [ 'VERSION' ] , app . config [ 'LATEST_VERSION' ] , resource_def [ 'id_field' ] , app . config [ 'LAST_UPDATED' ] , app . config [ 'DATE_CREATED' ] , app . config [ 'ETAG' ] , app . config [ 'LINKS' ] ] ) if ( resource_def [ 'soft_delete' ] is True ) : fields . append ( app . config [ 'DELETED' ] ) for field in fields : if ( ( field in new_doc ) and ( ( field not in old_doc ) or ( new_doc [ field ] != old_doc [ field ] ) ) ) : diff [ field ] = new_doc [ field ] for field in app . config [ 'VERSION_DIFF_INCLUDE' ] : if ( field in new_doc ) : diff [ field ] = new_doc [ field ] return diff
returns a list of added or modified fields .