def awesomebar_autocomplete_handler(request): """Accepts HTTP GET request with q=.. url arg, and returns suggestions""" query = request.GET.get('q') if not query: return create_json_response({'matches': {}}) categories = request.GET.get('categories').split(',') if request.GET.get( 'categories') else DEFAULT_CATEGORIES project_guids = get_project_guids_user_can_view(request.user) if any( category for category in categories if category in PROJECT_SPECIFIC_CATEGORY_MAP) else None results = { category: { 'name': _to_title_case(category), 'results': CATEGORY_MAP[category](query, project_guids) } for category in categories } return create_json_response( {'matches': {k: v for k, v in results.items() if v['results']}})
def awesomebar_autocomplete_handler(request): """Accepts HTTP GET request with q=.. url arg, and returns suggestions""" query = request.GET.get('q') if query is None: raise ValueError("missing ?q=<prefix> url arg") categories = request.GET.get('categories').split(',') if request.GET.get('categories') else CATEGORY_MAP.keys() results = { category: {'name': _to_title_case(category), 'results': CATEGORY_MAP[category](request.user, query)} for category in categories } return create_json_response({'matches': {k: v for k, v in results.items() if v['results']}})
def awesomebar_autocomplete_handler(request): """Accepts HTTP GET request with q=.. url arg, and returns suggestions""" query = request.GET.get('q') if query is None: raise ValueError("missing ?q=<prefix> url arg") categories = request.GET.get('categories').split(',') if request.GET.get( 'categories') else DEFAULT_CATEGORIES results = { category: { 'name': _to_title_case(category), 'results': CATEGORY_MAP[category](request.user, query) } for category in categories } return create_json_response( {'matches': {k: v for k, v in results.items() if v['results']}})