def list(request): db = DynamoDb() print "Calling list heatmaps. This should list out the existing heatmaps" result = db.get_key("heatmaps") heatmaps = [] if result and len(result['Items']) > 0: heatmaps = result['Items'] return heatmaps
def get(request, id): db = DynamoDb() result = db.get_key("heatmaps") if result and len(result['Items']) > 0: for item in result['Items']: for heatmap in item['value']: if heatmap['id'] == id: return heatmap return None
def post(request, meta): db = DynamoDb() heatmapArr = [] existingHeatmaps = db.get_key("heatmaps") heatmapArr = existingHeatmaps['Items'][0]['value'] # TODO: Remove [0] if testing fails heatmapArr.append({"id": meta['id'], "heatmap": meta}) return db.set("heatmaps", heatmapArr)
def delete(request, id): db = DynamoDb() existingHeatmaps = db.get_key("heatmaps") heatmapArr = existingHeatmaps['Items'][0]['value'] print heatmapArr for heatmap in heatmapArr: if heatmap['id'] == id: heatmapArr.remove(heatmap) print heatmapArr return db.set("heatmaps", heatmapArr)
def put(request, id, meta): db = DynamoDb() existingHeatmaps = db.get_key("heatmaps") heatmapArr = existingHeatmaps['Items'][0]['value'] newHeatmap = {"id": meta['id'], "heatmap": meta} heatmapArr = [ newHeatmap if heatmap['id'] == id else heatmap for heatmap in heatmapArr ] return db.set("heatmaps", heatmapArr)
def get(request, facetid): db = DynamoDb() result = db.get_key(facetid) result = json.dumps(result, cls=util.DynamoDbDecoder) return result