def get_directory(user, parent_path): # TODO: Add realm protection. url_prefix = request.url_root + 'v1' links = {'self': {'href': request.base_url}} # Check to make sure the requested path exists. parent_path = parent_path.strip('/') parent_path = parent_path + "/" requested_path = TimeSeriesPath.find({'user_id': user['_id'], 'parent_path': parent_path }) if requested_path and requested_path.count() > 0: # Get all the timeseries paths that have the specified parent path. for path in TimeSeriesPath.get_collection().aggregate( [{'$match': {"user_id": user['_id'], "parent_path": parent_path}}, {'$group': {'_id': {'name':'$name', 'title':'$title'}}}] )['result']: links[path['_id']['name']] = { 'href': '%s/%s.json' % (url_prefix, (parent_path if parent_path else '') + path['_id']['name'])} # Include the title in the returned data if the path has one set. if 'title' in path['_id']: links[path['_id']['name']]['title'] = path['_id']['title'] return json.dumps({'_links': links}) else: abort(404)
def get_directory(user, parent_path): # TODO: Add realm protection. url_prefix = request.url_root + 'v1' links = {'self': {'href': request.base_url}} # Check to make sure the requested path exists. parent_path = parent_path.strip('/') parent_path = parent_path + "/" requested_path = TimeSeriesPath.find({ 'user_id': user['_id'], 'parent_path': parent_path }) if requested_path and requested_path.count() > 0: # Get all the timeseries paths that have the specified parent path. for path in TimeSeriesPath.get_collection().aggregate([{ '$match': { "user_id": user['_id'], "parent_path": parent_path } }, { '$group': { '_id': { 'name': '$name', 'title': '$title' } } }])['result']: links[path['_id']['name']] = { 'href': '%s/%s.json' % (url_prefix, (parent_path if parent_path else '') + path['_id']['name']) } # Include the title in the returned data if the path has one set. if 'title' in path['_id']: links[path['_id']['name']]['title'] = path['_id']['title'] return json.dumps({'_links': links}) else: abort(404)