예제 #1
0
def search_graphs1(request,
                   owner_email=None,
                   names=None,
                   nodes=None,
                   edges=None,
                   tags=None,
                   member_email=None,
                   is_public=None,
                   query=None,
                   limit=20,
                   offset=0,
                   order='desc',
                   sort='name'):
    sort_attr = getattr(db.Graph, sort if sort is not None else 'name')
    orber_by = getattr(db, order if order is not None else 'desc')(sort_attr)
    is_public = int(is_public) if is_public is not None else None

    if member_email is not None:
        member_user = users.controllers.get_user(request, member_email)
        if member_user is not None:
            group_ids = [
                group.id
                for group in users.controllers.get_groups_by_member_id(
                    request, member_user.id)
            ]
        else:
            raise Exception("User with given member_email doesnt exist.")
    else:
        group_ids = None

    if edges is not None:
        edges = [tuple(edge.split(':')) for edge in edges]

    if 'query' in query:
        s = Search(using=settings.ELASTIC_CLIENT, index='graphs')
        s.update_from_dict(query)
        s.source(False)
        graph_ids = [int(hit.meta.id) for hit in s.scan()]
    else:
        graph_ids = None

    total, graphs_list = db.find_graphs(request.db_session,
                                        owner_email=owner_email,
                                        graph_ids=graph_ids,
                                        is_public=is_public,
                                        group_ids=group_ids,
                                        names=names,
                                        nodes=nodes,
                                        edges=edges,
                                        tags=tags,
                                        limit=limit,
                                        offset=offset,
                                        order_by=orber_by)

    return total, graphs_list
예제 #2
0
def search_graphs(request, owner_email=None, member_email=None, names=None, is_public=None, nodes=None, edges=None,
                  tags=None, limit=20, offset=0, order='desc', sort='name'):
	sort_attr = getattr(db.Graph, sort if sort is not None else 'name')
	orber_by = getattr(db, order if order is not None else 'desc')(sort_attr)
	is_public = int(is_public) if is_public is not None else None

	if member_email is not None:
		member_user = users.controllers.get_user(request, member_email)
		if member_user is not None:
			group_ids = [group.id for group in users.controllers.get_groups_by_member_id(request, member_user.id)]
		else:
			raise Exception("User with given member_email doesnt exist.")
	else:
		group_ids = None
	if edges is not None:
		edges = [tuple(edge.split(':')) for edge in edges]

	# if names is not None and len(names) > 0:
	# 	s = Search(using=settings.ELASTIC_CLIENT, index='graphs').query("match", **{"object_data.string_name": "kegg"})
	# 	query = {
	# 		"query": {
	# 			"bool": {
	# 				"should": [
	# 					{
	# 						"query_string": {
	# 							"default_field" : "object_data.string_name",
	# 							"query": ' OR '.join([name.replace('%', '*') for name in names])
	# 						}
	# 					}
	# 				]
	# 			}
	# 		}
	# 	}
	# 	s.update_from_dict(query)
	# 	s.source(False)
	# 	graph_ids = [int(hit.meta.id) for hit in s.scan()]
	# else:
	# 	graph_ids=None

	total, graphs_list = db.find_graphs(request.db_session,
	                                    owner_email=owner_email,
	                                    names=names,
	                                    is_public=is_public,
	                                    group_ids=group_ids,
	                                    nodes=nodes,
	                                    edges=edges,
	                                    tags=tags,
	                                    limit=limit,
	                                    offset=offset,
	                                    order_by=orber_by)

	return total, graphs_list
예제 #3
0
def search_graphs(request, owner_email=None, member_email=None, names=None, is_public=None, nodes=None, edges=None,
                  tags=None, limit=20, offset=0, order='desc', sort='name'):
	sort_attr = getattr(db.Graph, sort if sort is not None else 'name')
	orber_by = getattr(db, order if order is not None else 'desc')(sort_attr)
	is_public = int(is_public) if is_public is not None else None

	if member_email is not None:
		member_user = users.controllers.get_user(request, member_email)
		if member_user is not None:
			group_ids = [group.id for group in users.controllers.get_groups_by_member_id(request, member_user.id)]
		else:
			raise Exception("User with given member_email doesnt exist.")
	else:
		group_ids = None
	if edges is not None:
		edges = [tuple(edge.split(':')) for edge in edges]

	# if names is not None and len(names) > 0:
	# 	s = Search(using=settings.ELASTIC_CLIENT, index='graphs').query("match", **{"object_data.string_name": "kegg"})
	# 	query = {
	# 		"query": {
	# 			"bool": {
	# 				"should": [
	# 					{
	# 						"query_string": {
	# 							"default_field" : "object_data.string_name",
	# 							"query": ' OR '.join([name.replace('%', '*') for name in names])
	# 						}
	# 					}
	# 				]
	# 			}
	# 		}
	# 	}
	# 	s.update_from_dict(query)
	# 	s.source(False)
	# 	graph_ids = [int(hit.meta.id) for hit in s.scan()]
	# else:
	# 	graph_ids=None

	total, graphs_list = db.find_graphs(request.db_session,
	                                    owner_email=owner_email,
	                                    names=names,
	                                    is_public=is_public,
	                                    group_ids=group_ids,
	                                    nodes=nodes,
	                                    edges=edges,
	                                    tags=tags,
	                                    limit=limit,
	                                    offset=offset,
	                                    order_by=orber_by)

	return total, graphs_list
예제 #4
0
def search_graphs_by_group_ids(request,
                               group_ids=None,
                               owner_email=None,
                               names=None,
                               nodes=None,
                               edges=None,
                               tags=None,
                               limit=None,
                               offset=None):
    if group_ids is None:
        raise Exception("Atleast one group id is required.")
    return db.find_graphs(request.db_session,
                          group_ids=group_ids,
                          owner_email=owner_email,
                          names=names,
                          nodes=nodes,
                          edges=edges,
                          tags=tags,
                          limit=limit,
                          offset=offset)
예제 #5
0
def search_graphs1(request, owner_email=None, names=None, nodes=None, edges=None, tags=None, member_email=None,
                   is_public=None, query=None, limit=20, offset=0, order='desc', sort='name'):
	sort_attr = getattr(db.Graph, sort if sort is not None else 'name')
	orber_by = getattr(db, order if order is not None else 'desc')(sort_attr)
	is_public = int(is_public) if is_public is not None else None

	if member_email is not None:
		member_user = users.controllers.get_user(request, member_email)
		if member_user is not None:
			group_ids = [group.id for group in users.controllers.get_groups_by_member_id(request, member_user.id)]
		else:
			raise Exception("User with given member_email doesnt exist.")
	else:
		group_ids = None

	if edges is not None:
		edges = [tuple(edge.split(':')) for edge in edges]

	if 'query' in query:
		s = Search(using=settings.ELASTIC_CLIENT, index='graphs')
		s.update_from_dict(query)
		s.source(False)
		graph_ids = [int(hit.meta.id) for hit in s.scan()]
	else:
		graph_ids = None

	total, graphs_list = db.find_graphs(request.db_session,
	                                    owner_email=owner_email,
	                                    graph_ids=graph_ids,
	                                    is_public=is_public,
	                                    group_ids=group_ids,
	                                    names=names,
	                                    nodes=nodes,
	                                    edges=edges,
	                                    tags=tags,
	                                    limit=limit,
	                                    offset=offset,
	                                    order_by=orber_by)

	return total, graphs_list
예제 #6
0
def search_graphs_by_group_ids(request, group_ids=None, owner_email=None, names=None, nodes=None, edges=None, tags=None,
                               limit=None, offset=None):
	if group_ids is None:
		raise Exception("Atleast one group id is required.")
	return db.find_graphs(request.db_session, group_ids=group_ids, owner_email=owner_email, names=names, nodes=nodes,
	                      edges=edges, tags=tags, limit=limit, offset=offset)