def insert_versioning_documents(resource, documents):
 resource_def = app.config['DOMAIN'][resource]
 _id = resource_def['id_field']
 if (resource_def['versioning'] is True):
  if (not isinstance(documents, list)):
   documents = [documents]
  request_auth_value = None
  auth = resource_def['authentication']
  auth_field = resource_def['auth_field']
  if (auth and auth_field):
   request_auth_value = auth.get_request_auth_value()
  version = app.config['VERSION']
  versioned_documents = []
  for (index, document) in enumerate(documents):
   ver_doc = {}
   fields = versioned_fields(resource_def)
   for field in document:
    if (field in fields):
     ver_doc[field] = document[field]
   ver_doc[versioned_id_field(resource_def)] = document[_id]
   ver_doc[version] = document[version]
   if request_auth_value:
    ver_doc[auth_field] = request_auth_value
   versioned_documents.append(ver_doc)
  source = resource_def['datasource']['source']
  versionable_resource_name = (source + app.config['VERSIONS'])
  app.data.insert(versionable_resource_name, versioned_documents)

def insert_versioning_documents ( resource , documents ) : resource_def = app . config [ 'DOMAIN' ] [ resource ] _id = resource_def [ 'id_field' ] if ( resource_def [ 'versioning' ] is True ) : if ( not isinstance ( documents , list ) ) : documents = [ documents ] request_auth_value = None auth = resource_def [ 'authentication' ] auth_field = resource_def [ 'auth_field' ] if ( auth and auth_field ) : request_auth_value = auth . get_request_auth_value ( ) version = app . config [ 'VERSION' ] versioned_documents = [ ] for ( index , document ) in enumerate ( documents ) : ver_doc = { } fields = versioned_fields ( resource_def ) for field in document : if ( field in fields ) : ver_doc [ field ] = document [ field ] ver_doc [ versioned_id_field ( resource_def ) ] = document [ _id ] ver_doc [ version ] = document [ version ] if request_auth_value : ver_doc [ auth_field ] = request_auth_value versioned_documents . append ( ver_doc ) source = resource_def [ 'datasource' ] [ 'source' ] versionable_resource_name = ( source + app . config [ 'VERSIONS' ] ) app . data . insert ( versionable_resource_name , versioned_documents )
insert versioning copy of document .