Example #1
0
File: base.py Project: harche/wok
    def index(self, *args, **kwargs):
        params = {}
        method = validate_method(('GET', 'POST'),
                                 self.role_key, self.admin_methods)

        try:
            if method == 'GET':
                params = cherrypy.request.params
                validate_params(params, self, 'get_list')
                return self.get(params)
            elif method == 'POST':
                params = parse_request()
                result = self.create(params, *args)

                # log request
                reqParams = utf8_dict(self.log_args, params)
                RequestRecord(
                    self.getRequestMessage(method) % reqParams,
                    app=get_plugin_from_request(),
                    req=method,
                    user=cherrypy.session.get(USER_NAME, 'N/A')
                ).log()

                return result
        except InvalidOperation, e:
            raise cherrypy.HTTPError(400, e.message)
Example #2
0
File: base.py Project: harche/wok
        def wrapper(*args, **kwargs):
            method = 'POST'
            validate_method((method), self.role_key, self.admin_methods)
            try:
                self.lookup()
                if not self.is_authorized():
                    raise UnauthorizedError('WOKAPI0009E')

                model_args = list(self.model_args)
                request = parse_request()
                validate_params(request, self, action_name)
                if action_args is not None:
                    model_args.extend(
                        request[key] if key in request.keys() else None
                        for key in action_args
                    )

                action_fn = getattr(self.model, model_fn(self, action_name))
                action_result = action_fn(*model_args)

                # log request
                reqParams = utf8_dict(self.log_args, request)
                RequestRecord(
                    self.getRequestMessage(method, action_name) % reqParams,
                    app=get_plugin_from_request(),
                    req=method,
                    user=cherrypy.session.get(USER_NAME, 'N/A')
                ).log()

                if destructive is False or \
                    ('persistent' in self.info.keys() and
                     self.info['persistent'] is True):
                    return render_fn(self, action_result)
            except MissingParameter, e:
                raise cherrypy.HTTPError(400, e.message)
Example #3
0
        def wrapper(*args, **kwargs):
            method = 'POST'
            validate_method((method), self.role_key, self.admin_methods)
            try:
                self.lookup()
                if not self.is_authorized():
                    raise UnauthorizedError('WOKAPI0009E')

                model_args = list(self.model_args)
                request = parse_request()
                validate_params(request, self, action_name)
                if action_args is not None:
                    model_args.extend(
                        request[key] if key in request.keys() else None
                        for key in action_args)

                action_fn = getattr(self.model, model_fn(self, action_name))
                action_result = action_fn(*model_args)

                # log request
                reqParams = utf8_dict(self.log_args, request)
                RequestRecord(
                    self.getRequestMessage(method, action_name) % reqParams,
                    app=get_plugin_from_request(),
                    req=method,
                    user=cherrypy.session.get(USER_NAME, 'N/A')).log()

                if destructive is False or \
                    ('persistent' in self.info.keys() and
                     self.info['persistent'] is True):
                    return render_fn(self, action_result)
            except MissingParameter, e:
                raise cherrypy.HTTPError(400, e.message)
Example #4
0
    def index(self, *args, **kwargs):
        params = {}
        method = validate_method(('GET', 'POST'), self.role_key,
                                 self.admin_methods)

        try:
            if method == 'GET':
                params = cherrypy.request.params
                validate_params(params, self, 'get_list')
                return self.get(params)
            elif method == 'POST':
                params = parse_request()
                result = self.create(params, *args)

                # log request
                reqParams = utf8_dict(self.log_args, params)
                RequestRecord(self.getRequestMessage(method) % reqParams,
                              app=get_plugin_from_request(),
                              req=method,
                              user=cherrypy.session.get(USER_NAME,
                                                        'N/A')).log()

                return result
        except InvalidOperation, e:
            raise cherrypy.HTTPError(400, e.message)
Example #5
0
File: base.py Project: lcorreia/wok
                action_result = action_fn(*model_args)
                status = 200

                if destructive is False or \
                    ('persistent' in self.info.keys() and
                     self.info['persistent'] is True):
                    result = render_fn(self, action_result)
                    status = cherrypy.response.status
                    return result
            except WokException, e:
                status = e.getHttpStatusCode()
                raise cherrypy.HTTPError(status, e.message)
            finally:
                # log request
                code = self.getRequestMessage(method, action_name)
                reqParams = utf8_dict(self.log_args, request)
                msg = WokMessage(code, reqParams).get_text(prepend_code=False)
                RequestRecord(
                    msg,
                    app=get_plugin_from_request(),
                    req=method,
                    status=status,
                    user=cherrypy.session.get(USER_NAME, 'N/A'),
                    ip=cherrypy.request.remote.ip
                ).log()

        wrapper.__name__ = action_name
        wrapper.exposed = True
        return wrapper

    def lookup(self):