Exemplo n.º 1
0
    def __process_delete(self):
        if not self.__shield_class.delete(self.__shield_class.info):
            raise exceptions.MethodNotFound()

        id_param = http.get_id(self.__request.path)
        try:
            return self._find_database(id_param).delete(id=id_param).to_json()

        except exceptions.HookException:
            raise exceptions.HookException()
        except:
            raise exceptions.ModelNotFound()
Exemplo n.º 2
0
    def __process_put(self):
        if not self.__shield_class.put(self.__shield_class.info):
            raise exceptions.MethodNotFound()

        id_param = http.get_id(self.__request.upath_info)
        entity_json = json.loads(self.__request.body)
        if not id_param:
            exceptions.PutRequiresIdOnJson()

        entity_json['id'] = id_param
        entity = self.__model.to_instance(entity_json)
        return entity.update(entity_json).to_json()
Exemplo n.º 3
0
    def __process_get(self):
        if not self.__shield_class.get(self.__shield_class.info):
            raise exceptions.MethodNotFound()

        id_param = http.get_id(self.__request.path)
        params = http.query_params_to_dict(self.__request)

        try:
            if not id_param:
                return [model.to_json() for model in self.__model.find(**params)]

            return self._find_database(id_param).to_json()
        except:
            raise exceptions.ModelNotFound()