예제 #1
0
파일: base.py 프로젝트: cbosdo/kimchi
    def update(self):
        try:
            update = getattr(self.model, model_fn(self, 'update'))
        except AttributeError:
            e = InvalidOperation('KCHAPI0003E', {'resource':
                                                 get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        params = parse_request()
        validate_params(params, self, 'update')

        if self.update_params is not None:
            invalids = [v for v in params.keys() if
                        v not in self.update_params]
            if invalids:
                msg_args = {'params': ", ".join(invalids),
                            'resource': get_class_name(self)}
                e = InvalidOperation('KCHAPI0004E', msg_args)
                raise cherrypy.HTTPError(405, e.message)

        args = list(self.model_args) + [params]
        ident = update(*args)
        self._redirect(ident)

        return self.get()
예제 #2
0
    def update(self):
        try:
            update = getattr(self.model, model_fn(self, 'update'))
        except AttributeError:
            e = InvalidOperation('KCHAPI0003E',
                                 {'resource': get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        params = parse_request()
        validate_params(params, self, 'update')

        if self.update_params is not None:
            invalids = [
                v for v in params.keys() if v not in self.update_params
            ]
            if invalids:
                msg_args = {
                    'params': ", ".join(invalids),
                    'resource': get_class_name(self)
                }
                e = InvalidOperation('KCHAPI0004E', msg_args)
                raise cherrypy.HTTPError(405, e.message)

        args = list(self.model_args) + [params]
        ident = update(*args)
        self._redirect(ident)

        return self.get()
예제 #3
0
파일: base.py 프로젝트: Brainiarc7/kimchi
 def index(self, *args, **kwargs):
     method = validate_method(('GET', 'POST'))
     if method == 'GET':
         try:
             filter_params = cherrypy.request.params
             validate_params(filter_params, self, 'get_list')
             return self.get(filter_params)
         except InvalidOperation, e:
             raise cherrypy.HTTPError(400, e.message)
         except NotFoundError, e:
             raise cherrypy.HTTPError(404, e.message)
예제 #4
0
 def index(self, *args, **kwargs):
     method = validate_method(('GET', 'POST'))
     try:
         if method == 'GET':
             filter_params = cherrypy.request.params
             validate_params(filter_params, self, 'get_list')
             return self.get(filter_params)
         elif method == 'POST':
             return self.create(parse_request(), *args)
     except InvalidOperation, e:
         raise cherrypy.HTTPError(400, e.message)
예제 #5
0
 def index(self, *args, **kwargs):
     method = validate_method(('GET', 'POST'))
     if method == 'GET':
         try:
             filter_params = cherrypy.request.params
             validate_params(filter_params, self, 'get_list')
             return self.get(filter_params)
         except InvalidOperation, e:
             raise cherrypy.HTTPError(400, e.message)
         except NotFoundError, e:
             raise cherrypy.HTTPError(404, e.message)
예제 #6
0
파일: base.py 프로젝트: shaohef/kimchi
 def index(self, *args, **kwargs):
     method = validate_method(('GET', 'POST'))
     try:
         if method == 'GET':
             filter_params = cherrypy.request.params
             validate_params(filter_params, self, 'get_list')
             return self.get(filter_params)
         elif method == 'POST':
             return self.create(parse_request(), *args)
     except InvalidOperation, e:
         raise cherrypy.HTTPError(400, e.message)
예제 #7
0
파일: base.py 프로젝트: mprostko/kimchi
 def index(self, *args, **kwargs):
     method = validate_method(('GET', 'POST'))
     if method == 'GET':
         try:
             filter_params = cherrypy.request.params
             validate_params(filter_params, self, 'get_list')
             return self.get(filter_params)
         except InvalidOperation, param:
             error = "Invalid operation: '%s'" % param
             raise cherrypy.HTTPError(400, error)
         except NotFoundError, param:
             raise cherrypy.HTTPError(404, "Not found: '%s'" % param)
예제 #8
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            e = InvalidOperation('KCHAPI0005E',
                                 {'resource': get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        task = create(*args)
        cherrypy.response.status = 202
        return kimchi.template.render("Task", task)
예제 #9
0
파일: base.py 프로젝트: cbosdo/kimchi
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            e = InvalidOperation('KCHAPI0005E', {'resource':
                                                 get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        task = create(*args)
        cherrypy.response.status = 202
        return kimchi.template.render("Task", task)
예제 #10
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            e = InvalidOperation('KCHAPI0005E',
                                 {'resource': get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        name = create(*args)
        cherrypy.response.status = 201
        args = self.resource_args + [name]
        res = self.resource(self.model, *args)

        return res.get()
예제 #11
0
    def update(self, *args, **kargs):
        try:
            update = getattr(self.model, model_fn(self, 'update'))
        except AttributeError:
            e = InvalidOperation('KCHAPI0003E',
                                 {'resource': get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        params = parse_request()
        validate_params(params, self, 'update')

        args = list(self.model_args) + [params]
        ident = update(*args)
        self._redirect(ident)

        return self.get()
예제 #12
0
파일: base.py 프로젝트: cbosdo/kimchi
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            e = InvalidOperation('KCHAPI0005E', {'resource':
                                                 get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        name = create(*args)
        cherrypy.response.status = 201
        args = self.resource_args + [name]
        res = self.resource(self.model, *args)

        return res.get()
예제 #13
0
파일: base.py 프로젝트: melmorabity/kimchi
    def update(self, *args, **kargs):
        try:
            update = getattr(self.model, model_fn(self, 'update'))
        except AttributeError:
            e = InvalidOperation('KCHAPI0003E', {'resource':
                                                 get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        params = parse_request()
        validate_params(params, self, 'update')

        args = list(self.model_args) + [params]
        ident = update(*args)
        self._redirect(ident)

        return self.get()
예제 #14
0
파일: base.py 프로젝트: mprostko/kimchi
    def create(self, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            error = 'Create is not allowed for %s' % get_class_name(self)
            raise cherrypy.HTTPError(405, error)

        params = parse_request()
        validate_params(params, self, 'create')
        args = self.model_args + [params]
        name = create(*args)
        cherrypy.response.status = 201
        args = self.resource_args + [name]
        res = self.resource(self.model, *args)

        return res.get()
예제 #15
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            error = 'Create is not allowed for %s' % get_class_name(self)
            raise cherrypy.HTTPError(405, error)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        name = create(*args)
        args = self.resource_args + [name]
        res = self.resource(self.model, *args)
        resp = res.get()

        if 'task_id' in res.data:
            cherrypy.response.status = 202
        else:
            cherrypy.response.status = 201

        return resp
예제 #16
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            error = 'Create is not allowed for %s' % get_class_name(self)
            raise cherrypy.HTTPError(405, error)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        name = create(*args)
        args = self.resource_args + [name]
        res = self.resource(self.model, *args)
        resp = res.get()

        if 'task_id' in res.data:
            cherrypy.response.status = 202
        else:
            cherrypy.response.status = 201

        return resp
예제 #17
0
파일: base.py 프로젝트: mprostko/kimchi
    def update(self):
        try:
            update = getattr(self.model, model_fn(self, 'update'))
        except AttributeError:
            error = "%s does not implement update method"
            raise cherrypy.HTTPError(405, error % get_class_name(self))

        params = parse_request()
        validate_params(params, self, 'update')

        if self.update_params is not None:
            invalids = [v for v in params.keys() if
                        v not in self.update_params]
            if invalids:
                error = "%s are not allowed to be updated" % invalids
                raise cherrypy.HTTPError(405, error)

        ident = update(self.ident, params)
        if ident != self.ident:
            uri_params = list(self.model_args[:-1])
            uri_params += [urllib2.quote(ident.encode('utf8'))]
            raise cherrypy.HTTPRedirect(self.uri_fmt % tuple(uri_params), 303)

        return self.get()