def search_nodes(request, graph_id=None, names=None, labels=None, limit=20, offset=0, order='desc', sort='name'): if sort == 'name': sort_attr = db.Node.name elif sort == 'update_at': sort_attr = db.Node.updated_at elif sort == 'label': sort_attr = db.Node.label else: sort_attr = db.Node.name if order == 'desc': orber_by = db.desc(sort_attr) else: orber_by = db.asc(sort_attr) ## TODO: create a util function to relpace the code parse sort and order parameters. This code is repeated again and again. total, nodes = db.find_nodes(request.db_session, names=names, labels=labels, graph_id=graph_id, limit=limit, offset=offset, order_by=orber_by) return total, nodes
def _convert_order_query_term_to_database_order_object(order_query): """ It converts terms like owner_descending to desc(Graph.owner_email) which is readable by sqlalchemy. Parameters ---------- order_query: order query eg: owner_descending Returns ------- order object like desc(Graph.owner_email) """ order_query = '' if order_query is None else order_query if 'owner' in order_query: attribute = db.Graph.owner_email elif 'graph' in order_query: attribute = db.Graph.name else: attribute = db.Graph.updated_at if 'ascending' in order_query: return db.asc(attribute) else: return db.desc(attribute)
def search_layouts(request, owner_email=None, is_shared=None, name=None, graph_id=None, limit=20, offset=0, order='desc', sort='name'): if sort == 'name': sort_attr = db.Layout.name elif sort == 'update_at': sort_attr = db.Layout.updated_at elif sort == 'owner_email': sort_attr = db.Layout.owner_email else: sort_attr = db.Layout.name if order == 'desc': orber_by = db.desc(sort_attr) else: orber_by = db.asc(sort_attr) total, layouts = db.find_layouts(request.db_session, owner_email=owner_email, is_shared=is_shared, name=name, graph_id=graph_id, limit=limit, offset=offset, order_by=orber_by) return total, layouts
def search_edges(request, is_directed=None, names=None, edges=None, graph_id=None, limit=20, offset=0, order='desc', sort='name'): if sort == 'name': sort_attr = db.Edge.name elif sort == 'update_at': sort_attr = db.Edge.updated_at else: sort_attr = db.Edge.name if order == 'desc': orber_by = db.desc(sort_attr) else: orber_by = db.asc(sort_attr) if edges is not None: edges = [tuple(edge.split(':')) for edge in edges] ## TODO: create a util function to relpace the code parse sort and order parameters. This code is repeated again and again. total, edges = db.find_edges(request.db_session, names=names, edges=edges, is_directed=is_directed, graph_id=graph_id, limit=limit, offset=offset, order_by=orber_by) return total, edges