def _update_dash(self, dash_id, data): current_time = time.time() meta = json.loads(r_db.hget(config.DASH_META_KEY, dash_id)) meta.update({'name': '' + data['name'], 'time_modified': int(current_time)}) content = json.loads(r_db.hget(config.DASH_CONTENT_KEY, dash_id)) content.update(data) r_db.hset(config.DASH_META_KEY, dash_id, json.dumps(meta)) r_db.hset(config.DASH_CONTENT_KEY, dash_id, json.dumps(data)) updated = { "meta": r_db.hget(config.DASH_META_KEY, dash_id), "content": r_db.hget(config.DASH_CONTENT_KEY, dash_id), } return updated
def delete(self, dash_id): """Delete a dash meta and content, return updated dash content. Actually, just remove it to a specfied place in database. Args: dash_id: dashboard id. Returns: Redirect to home page. """ removed_info = dict( time_modified = r_db.zscore(config.DASH_ID_KEY, dash_id), meta = r_db.hget(config.DASH_META_KEY, dash_id), content = r_db.hget(config.DASH_CONTENT_KEY, dash_id)) r_db.zrem(config.DASH_ID_KEY, dash_id) r_db.hdel(config.DASH_META_KEY, dash_id) r_db.hdel(config.DASH_CONTENT_KEY, dash_id) return {'removed_info': removed_info}
def _update_dash(self, dash_id, data): current_time = time.time() meta = json.loads(r_db.hget(config.DASH_META_KEY, dash_id)) meta.update({ 'name': '' + data['name'], 'time_modified': int(current_time) }) content = json.loads(r_db.hget(config.DASH_CONTENT_KEY, dash_id)) content.update(data) r_db.hset(config.DASH_META_KEY, dash_id, json.dumps(meta)) r_db.hset(config.DASH_CONTENT_KEY, dash_id, json.dumps(data)) updated = { "meta": r_db.hget(config.DASH_META_KEY, dash_id), "content": r_db.hget(config.DASH_CONTENT_KEY, dash_id), } return updated
def delete(self, dash_id): """Delete a dash meta and content, return updated dash content. Actually, just remove it to a specfied place in database. Args: dash_id: dashboard id. Returns: Redirect to home page. """ removed_info = dict(time_modified=r_db.zscore(config.DASH_ID_KEY, dash_id), meta=r_db.hget(config.DASH_META_KEY, dash_id), content=r_db.hget(config.DASH_CONTENT_KEY, dash_id)) r_db.zrem(config.DASH_ID_KEY, dash_id) r_db.hdel(config.DASH_META_KEY, dash_id) r_db.hdel(config.DASH_CONTENT_KEY, dash_id) return {'removed_info': removed_info}
def put(self, dash_id=0): """Update a dash meta and content, return updated dash content. Args: dash_id: dashboard id. Returns: A dict containing the updated content of that dashboard, not include the meta info. """ data = request.get_json() current_time = time.time() meta = json.loads(r_db.hget(config.DASH_META_KEY, dash_id)) meta.update({'name': '' + data['name'], 'time_modified': int(current_time)}) content = json.loads(r_db.hget(config.DASH_CONTENT_KEY, dash_id)) content.update(data) r_db.hset(config.DASH_META_KEY, dash_id, json.dumps(meta)) r_db.hset(config.DASH_CONTENT_KEY, dash_id, json.dumps(data)) return build_response(dict(data=dash_id, code=200))
def put(self, dash_id=0): """Update a dash meta and content, return updated dash content. Args: dash_id: dashboard id. Returns: A dict containing the updated content of that dashboard, not include the meta info. """ data = request.get_json() current_time = time.time() meta = json.loads(r_db.hget(config.DASH_META_KEY, dash_id)) meta.update({ 'name': '' + data['name'], 'time_modified': int(current_time) }) content = json.loads(r_db.hget(config.DASH_CONTENT_KEY, dash_id)) content.update(data) r_db.hset(config.DASH_META_KEY, dash_id, json.dumps(meta)) r_db.hset(config.DASH_CONTENT_KEY, dash_id, json.dumps(data)) return build_response(dict(data=dash_id, code=200))