def userEdges(user_id): entry = user.findUserByID(user_id) if entry is None: return '', HTTP_404_NOT_FOUND suggested_connections = [] pending_connections = [] pending_connections_messages = {} if user_id == 'me': suggested_connection_users = user.get_suggested_connections(entry) suggested_connections = user.get_basic_info_from_users(suggested_connection_users) pending_connection_ids = map(lambda connection : ObjectId(connection['user']), user.get_pending_connections(entry)) pending_connections = user.get_basic_info_from_ids(pending_connection_ids) map(lambda connection: pending_connections_messages.update({connection['user']:connection['message']}), user.get_pending_connections(entry)) connection_ids = map(ObjectId, user.get_connections(entry)) connections = user.get_basic_info_from_ids(connection_ids) annotated = {'connections': connections, 'suggestedConnections': suggested_connections, 'pendingConnections': pending_connections, 'pendingConnectionsMessages': pending_connections_messages, 'associations': []} return jsonify(**annotated)
def get_details(startup_object, current_user_id): qa = startup_object.qa if not is_owner(current_user_id, startup_object): # get only answered messages qa = filter(lambda q: q['status'] == Startup.question_status['ANSWERED'], qa) for qa_item in qa: asker_user = user.findUserByID(ObjectId(qa_item['asker'])) qa_item['asker'] = utils.jsonFields(asker_user, user.User.basic_info_fields, response=False) all_people_needed = set() annotated_wall = [] for wall_item in startup_object.wall: all_people_needed.add(wall_item['user']) annotated_wall_item = wall_item.copy() annotated_wall_item['user'] = str(annotated_wall_item['user']) annotated_wall.append(annotated_wall_item) users = {} for basic_info in user.get_basic_info_from_ids(list(all_people_needed)): users[basic_info['_id']] = basic_info for wall_item in annotated_wall: wall_item['user'] = utils.jsonFields(users[wall_item['user']], user.User.basic_info_fields, response=False) people_info = user.get_basic_info_from_ids(map(ObjectId, startup_object.people)) return {'qa': qa, 'wall': annotated_wall, 'people': people_info, 'overview': startup_object.overview}
def search(): """ Takes url params as arguments. One of the arguments must be named "query_string". This argument is the actual query entered into the search bar. The rest of the arguments are optional and can be named anything. These arguments must contain single item json, i.e. {term:filter} where term is the name of the field to be filtered, and filter is the required string for that field. For example, /api/v1/search?query_string=hardware%20java%20ibm&role=programmer&firstName=tanner&results_per_page=5&page=7 will search for all users that have the words hardware, java, and ibm anywhere in their information, and it will then filter those results to only results that have the role set to "programmer" and the firstName set to "tanner". Setting the results_per_page and page behaves as you would expect it to. Indexing for pagination starts at 0. Results are returned in the form of a list of json results. """ error = None list_filters = [] try: query_string = request.args.get('query_string') results_per_page = request.args.get('results_per_page') page = request.args.get('page') keyed_queries = {} for constraint, value in request.args.items(): if constraint == 'query_string' or constraint == 'results_per_page' or constraint == 'page': continue keyed_queries[constraint] = value.lower() if query_string is not None: query_string = query_string.lower() if results_per_page is not None: results_per_page = int(results_per_page) if page is not None: page = int(page) if keyed_queries: results = search_functions.filtered_search_users(query_string, [{'term':keyed_queries}], results_per_page, page) else: #call basic search results = search_functions.simple_search_users(query_string, results_per_page, page) except Exception as e: return jsonify(error=str(e)), HTTP_400_BAD_REQUEST ## now turn the queries into basic users user_ids = map(ObjectId, (entry['_id'] for entry in results.data)) #TODO: Why can't we inject endorsements into the objects returned from elastic? basic_users = user.get_basic_info_from_ids(user_ids, keep_order=True) endorsement.populate_counts(basic_users) return dumps({'results': basic_users, 'metadata': results.metadata, 'error': None})
def userEdges(user_id): entry = user.findUserByID(user_id) if entry is None: return '', HTTP_404_NOT_FOUND suggested_connections = [] pending_connections = [] pending_connections_messages = {} if user_id == 'me': suggested_connection_users = user.get_suggested_connections(entry) suggested_connections = user.get_basic_info_from_users( suggested_connection_users) pending_connection_ids = map( lambda connection: ObjectId(connection['user']), user.get_pending_connections(entry)) pending_connections = user.get_basic_info_from_ids( pending_connection_ids) map( lambda connection: pending_connections_messages.update( {connection['user']: connection['message']}), user.get_pending_connections(entry)) connection_ids = map(ObjectId, user.get_connections(entry)) connections = user.get_basic_info_from_ids(connection_ids) annotated = { 'connections': connections, 'suggestedConnections': suggested_connections, 'pendingConnections': pending_connections, 'pendingConnectionsMessages': pending_connections_messages, 'associations': [] } return jsonify(**annotated)
def search(): """ Takes url params as arguments. One of the arguments must be named "query_string". This argument is the actual query entered into the search bar. The rest of the arguments are optional and can be named anything. These arguments must contain single item json, i.e. {term:filter} where term is the name of the field to be filtered, and filter is the required string for that field. For example, /api/v1/search?query_string=hardware%20java%20ibm&role=programmer&firstName=tanner&results_per_page=5&page=7 will search for all users that have the words hardware, java, and ibm anywhere in their information, and it will then filter those results to only results that have the role set to "programmer" and the firstName set to "tanner". Setting the results_per_page and page behaves as you would expect it to. Indexing for pagination starts at 0. Results are returned in the form of a list of json results. """ error = None list_filters = [] try: query_string = request.args.get('query_string') results_per_page = request.args.get('results_per_page') page = request.args.get('page') keyed_queries = {} for constraint, value in request.args.items(): if constraint == 'query_string' or constraint == 'results_per_page' or constraint == 'page': continue keyed_queries[constraint] = value.lower() if query_string is not None: query_string = query_string.lower() if results_per_page is not None: results_per_page = int(results_per_page) if page is not None: page = int(page) if keyed_queries: results = search_functions.filtered_search_users( query_string, [{ 'term': keyed_queries }], results_per_page, page) else: #call basic search results = search_functions.simple_search_users( query_string, results_per_page, page) except Exception as e: return jsonify(error=str(e)), HTTP_400_BAD_REQUEST ## now turn the queries into basic users user_ids = map(ObjectId, (entry['_id'] for entry in results.data)) #TODO: Why can't we inject endorsements into the objects returned from elastic? basic_users = user.get_basic_info_from_ids(user_ids, keep_order=True) endorsement.populate_counts(basic_users) return dumps({ 'results': basic_users, 'metadata': results.metadata, 'error': None })