def create_vote(**request_handler_args): req = request_handler_args['req'] resp = request_handler_args['resp'] params = json.loads(req.stream.read().decode('utf-8')) curr_sess = 0 if 'fingerprint' in params and 'value' in params and 'session' in params: try: curr_sessions = get_current_session_id() curr_sess = curr_sessions[0] if len(curr_sessions) else -1 if curr_sess != params['session']: raise Exception('Only current session allowed') id = EntityVote(curr_sess, params['fingerprint'], params['value']).add() if id: cache.invalidate(get_vote_objects, 'get_vote_func', curr_sess, params['fingerprint']) except: resp.body = obj_to_json([]) resp.status = falcon.HTTP_404 resp.body = obj_to_json(get_vote_objects(curr_sess, params['fingerprint'])) resp.status = falcon.HTTP_200 return
def set_session(**request_handler_args): resp = request_handler_args['resp'] try: value = getIntPathParam('id', **request_handler_args) EntityCurrentSession.update_from_params({'curr_id': value}) cache.invalidate(get_current_session_id, 'get_current_session_group') cache.invalidate(get_current_session_object, 'get_current_session_group_object') resp.body = obj_to_json(get_current_session_id()) resp.status = falcon.HTTP_200 return None except Exception as e: resp.body = obj_to_json({'message': str(e)}) resp.status = falcon.HTTP_400 return None
def update_session(**request_handler_args): req = request_handler_args['req'] resp = request_handler_args['resp'] try: params = {} for _ in req.params.keys(): if _ == 'image': params[_] = req.get_param(_).file.read() else: params[_] = req.get_param(_) id = EntitySession.update_from_params(params) if id: cache.invalidate(get_session_objects, 'get_session_func', id) cache.invalidate(get_current_session_object, 'get_current_session_group_object') resp.body = obj_to_json(get_session_objects(id)) resp.status = falcon.HTTP_200 return except ValueError: resp.status = falcon.HTTP_405 return resp.status = falcon.HTTP_501
def get_session(**request_handler_args): resp = request_handler_args['resp'] id = getIntPathParam("id", **request_handler_args) if id: resp.body = obj_to_json(get_session_objects(id)) resp.status = falcon.HTTP_200 return resp.status = falcon.HTTP_400
def get_vote(**request_handler_args): resp = request_handler_args['resp'] session = getIntPathParam("session", **request_handler_args) fingerprint = getPathParam("fingerprint", **request_handler_args) if id: resp.body = obj_to_json(get_vote_objects(session, fingerprint)) resp.status = falcon.HTTP_200 return resp.status = falcon.HTTP_400
def parse_plan(**request_handler_args): resp = request_handler_args['resp'] id = getIntPathParam("id", **request_handler_args) if id: obj = OrderedDict([('vid', str(id)), ('image', base_name + '/images/parsed_plan' + str(id) + '.png')]) resp.body = obj_to_json(obj) resp.status = falcon.HTTP_200 time.sleep(4) return resp.status = falcon.HTTP_400
def get_stats_by_id(**request_handler_args): resp = request_handler_args['resp'] id = getIntPathParam('id', **request_handler_args) entity = get_session_objects(id) obj_dict = [] if len(entity): stats = get_cached_stats(id, entity[0]["type"]) obj_dict = entity[0] obj_dict.update({'stats': stats}) obj_dict = [obj_dict] resp.body = obj_to_json(obj_dict) resp.status = falcon.HTTP_200
def create_fingerprint(**request_handler_args): resp = request_handler_args['resp'] try: fingerprint = getIntPathParam("fingerprint", **request_handler_args) id = EntityUser(fingerprint).add() if id: resp.body = obj_to_json([o.to_dict() for o in EntityUser.get().filter_by(vid=id).all()]) resp.status = falcon.HTTP_200 return except ValueError: resp.status = falcon.HTTP_405 return resp.status = falcon.HTTP_501
def create_session(**request_handler_args): req = request_handler_args['req'] resp = request_handler_args['resp'] try: params = {} for _ in req.params.keys(): if _ == 'image': params[_] = req.get_param(_).file.read() else: params[_] = req.get_param(_) id = EntitySession.add_from_params(params) if id: resp.body = obj_to_json([o.to_dict() for o in fulfill_images(base_name, EntitySession.get().filter_by(vid=id).all())]) resp.status = falcon.HTTP_200 return except ValueError: resp.status = falcon.HTTP_405 return resp.status = falcon.HTTP_501
def getVersion(**request_handler_args): resp = request_handler_args['resp'] resp.status = falcon.HTTP_200 with open("VERSION") as f: resp.body = obj_to_json({"version": f.read()[0:-1]})
def current_session_object(**request_handler_args): resp = request_handler_args['resp'] resp.body = obj_to_json(get_current_session_object()) resp.status = falcon.HTTP_200
def all_session(**request_handler_args): resp = request_handler_args['resp'] resp.body = obj_to_json([o.to_dict() for o in fulfill_images(base_name, EntitySession.get().all())]) resp.status = falcon.HTTP_200