예제 #1
0
파일: api.py 프로젝트: skftn/findex-gui
class SessionSet(Resource):
    def __init__(self):
        self.reqparse = reqparse.RequestParser()

        self.reqparse.add_argument('key', location='json', type=str, required=True, help='key is required')
        self.reqparse.add_argument('val', location='json', type=str, required=True, help='value is required')

        super(SessionSet, self).__init__()

    def post(self):
        args = self.reqparse.parse_args()
        args = {k: v for k, v in args.items() if v is not None}

        if not args['key'] in keys:
            return abort(404, message="key \"%s\" doesn't exist" % args['key'])

        if not args['val'] in ['table', 'fancy']:
            return abort(404, message="could not set val \"%s\" - doesn't exist" % args['val'])

        session[args['key']] = args['val']
        print session[args['key']]

        return flask.jsonify(**{
            'message': 'ok'
        })

appapi.add_resource(SessionSet, '/api/v2/session/set', endpoint='api_session_set')
appapi.add_resource(SessionGet, '/api/v2/session/get', endpoint='api_session_get')

예제 #2
0
파일: api.py 프로젝트: skftn/findex-gui
    def post(self):
        args = self.reqparse.parse_args()
        args = {k: v for k, v in args.items() if v is not None}

        user = UserController.user_add(username=args['username'], password=args['password'])
        if isinstance(user, Exception):
            return abort(404, message=str(user))
        else:
            return flask.jsonify(**{'success': True})


class UserDelete(Resource):
    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument('username', location='json', type=str, required=True, help='Username')
        super(UserDelete, self).__init__()

    def post(self):
        args = self.reqparse.parse_args()
        args = {k: v for k, v in args.items() if v is not None}

        user = UserController.user_delete(username=args['username'])
        if isinstance(user, Exception):
            return abort(404, message=str(user))
        else:
            return flask.jsonify(**args)

appapi.add_resource(UserRegister, '/api/v2/user/delete', endpoint='api_user_delete')
appapi.add_resource(UserRegister, '/api/v2/user/register', endpoint='api_user_register')
예제 #3
0
파일: api.py 프로젝트: skftn/findex-gui
class OptionsPostAPI(Resource):
    decorators = [admin_required]
    keys = [
        'theme_active',
    ]

    def __init__(self):
        self.reqparse = reqparse.RequestParser()

        self.reqparse.add_argument('key', location='json', type=str, required=True, help='key is required')
        self.reqparse.add_argument('val', location='json', type=str, required=True, help='key is required')

        super(OptionsPostAPI, self).__init__()

    def post(self):
        global keys

        args = self.reqparse.parse_args()
        args = {k: v for k, v in args.items() if v is not None}

        if not args['key'] in keys:
            return abort(404, message='Unknown key \'%s\'' % args['key'])

        OptionsController.set(key=args['key'],
                              val=args['val'])

        return flask.jsonify(**{'message': 'key set'})


appapi.add_resource(OptionsPostAPI, '/api/v2/admin/option_set', endpoint='api_admin_option_set')
appapi.add_resource(OptionsGetAPI, '/api/v2/admin/option_get', endpoint='api_admin_option_get')
예제 #4
0
파일: api.py 프로젝트: skftn/findex-gui
                                   help='Set to true for better search performance but less accuracy. Most suited ' +
                                   'for auto completion on the front-end.')

        self.reqparse.add_argument('autocomplete', type=bool, location='json',
                                   help='this is the same as setting `lazy_search` to true and `per_page` to 5')

        super(SearchAPI, self).__init__()

    def get(self, key):
        controller = SearchController()
        result = controller.search(key=key)

        return flask.jsonify(**result.make_dict())

    def post(self, key):
        # ---- make decorator of this with try catch oin parse_args (it can fail)
        args = self.reqparse.parse_args()

        args = {k: v for k, v in args.items() if v is not None}
        # ----

        try:
            controller = SearchController()
            result = controller.search(key, **args)
        except Exception as ex:
            return abort(404, message=str(ex))

        return flask.jsonify(**result.make_dict())

appapi.add_resource(SearchAPI, '/api/v2/search/<string:key>', endpoint='api_search')