def embedded_document(reference, data_relation, field_name):
 if (('version' in data_relation) and (data_relation['version'] is True)):
  embedded_doc = get_data_version_relation_document(data_relation, reference)
  latest_embedded_doc = get_data_version_relation_document(data_relation, reference, latest=True)
  if ((embedded_doc is None) or (latest_embedded_doc is None)):
   abort(404, description=debug_error_message(("Unable to locate embedded documents for '%s'" % field_name)))
  build_response_document(embedded_doc, data_relation['resource'], [], latest_embedded_doc)
 else:
  subresource = (reference.collection if isinstance(reference, DBRef) else data_relation['resource'])
  id_field = config.DOMAIN[subresource]['id_field']
  embedded_doc = app.data.find_one(subresource, None, **{id_field: (reference.id if isinstance(reference, DBRef) else reference)})
  if embedded_doc:
   resolve_media_files(embedded_doc, subresource)
 return embedded_doc

def embedded_document ( reference , data_relation , field_name ) : if ( ( 'version' in data_relation ) and ( data_relation [ 'version' ] is True ) ) : embedded_doc = get_data_version_relation_document ( data_relation , reference ) latest_embedded_doc = get_data_version_relation_document ( data_relation , reference , latest = True ) if ( ( embedded_doc is None ) or ( latest_embedded_doc is None ) ) : abort ( 404 , description = debug_error_message ( ( "Unable to locate embedded documents for '%s'" % field_name ) ) ) build_response_document ( embedded_doc , data_relation [ 'resource' ] , [ ] , latest_embedded_doc ) else : subresource = ( reference . collection if isinstance ( reference , DBRef ) else data_relation [ 'resource' ] ) id_field = config . DOMAIN [ subresource ] [ 'id_field' ] embedded_doc = app . data . find_one ( subresource , None , ** { id_field : ( reference . id if isinstance ( reference , DBRef ) else reference ) } ) if embedded_doc : resolve_media_files ( embedded_doc , subresource ) return embedded_doc
returns a document to be embedded by reference using data_relation taking into account document versions .