예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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
예제 #6
0
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
예제 #7
0
def delete_session(**request_handler_args):
    resp = request_handler_args['resp']

    id = getIntPathParam("id", **request_handler_args)

    if id is not None:
        try:
            EntitySession.delete(id)
        except FileNotFoundError:
            resp.status = falcon.HTTP_404
            return

        object = EntitySession.get().filter_by(vid=id).all()
        if not len(object):
            resp.status = falcon.HTTP_200
            cache.invalidate(get_session_objects, 'get_session_func', id)
            return

    resp.status = falcon.HTTP_400
예제 #8
0
def reset_session(**request_handler_args):
    resp = request_handler_args['resp']

    id = getIntPathParam("id", **request_handler_args)

    if id is not None:
        try:
            with DBConnection() as db_session:
                fp = db_session.db.query(EntityVote).filter_by(session=id).all()
                db_session.db.query(EntityVote).filter_by(session=id).delete()
                db_session.db.commit()

            resp.status = falcon.HTTP_200
            cache.invalidate(get_session_objects, 'get_session_func', id)
            for _ in fp:
                cache.invalidate(get_vote_objects, 'get_vote_func', id, _.user)
            return

        except FileNotFoundError:
            resp.status = falcon.HTTP_404
            return

    resp.status = falcon.HTTP_400