Beispiel #1
0
    def dispatch_creation(self, method, request, *args, **kwargs):
        # Expected to be in the form of one of the following:
        # 0.  None
        # 1.  ResourceResponse
        # 2.  ResourceResponse, created (bool)
        # 3.  Object
        # 4.  Object, created (bool)
        ret = self.dispatch_method(
            method, request, wrap_response=False, *args, **kwargs)
        created = False

        if isinstance(ret, ResourceResponse):
            resp = ret
        elif isinstance(ret, collections.Iterable):
            if len(ret) == 2:
                resp = ret[0]

                if resp is not None:
                    created = ret[1]
                    if not isinstance(resp, ResourceResponse):
                        resp = ResourceResponse(resp)
            else:
                raise WrongNumberOfValues('Must return 1 or 2 values')
        elif ret is not None:
            resp = ResourceResponse(ret)
        else:
            resp = None

        if resp is not None:
            return self.create_http_response(request, resp, created=created)
Beispiel #2
0
    def post(self, request, *args, **kwargs):
        cake = self.create_obj(request, *args, **kwargs)

        return ResourceResponse(cake,
                                response_cls=HttpCreated,
                                response_kwargs={
                                    'location':
                                    lambda entity: entity.get_resource_uri()
                                })
Beispiel #3
0
    def dispatch_method(self, method, request,
                        wrap_response=True, *args, **kwargs):
        self.process_body(request)
        resource_resp = method(request, *args, **kwargs)

        self.raise_if_http_response(resource_resp)

        if wrap_response and resource_resp is not None and \
                not isinstance(resource_resp, ResourceResponse):
            resource_resp = ResourceResponse(resource_resp)

        return resource_resp
 def put(self, request, *args, **kwargs):
     return ResourceResponse(self._put(request, *args, **kwargs),
                             entity_cls=CakeDetailEntity)
 def post(self, request, *args, **kwargs):
     return ResourceResponse(self.create_obj(request, *args, **kwargs),
                             entity_cls=CakeDetailEntity), True
 def get(self, request, *args, **kwargs):
     return ResourceResponse(self._get(request, *args, **kwargs),
                             entity_cls=CakeListEntity)
 def put(self, request, *args, **kwargs):
     cake, created = self._put(request, *args, **kwargs)
     return ResourceResponse(cake, entity_cls=CakeDetailEntity), created
Beispiel #8
0
 def head(self, request, *args, **kwargs):
     return ResourceResponse(self._head(request, *args, **kwargs),
                             include_entity=True)
Beispiel #9
0
 def put(self, request, *args, **kwargs):
     cake, created = self._put(request, *args, **kwargs)
     return ResourceResponse(cake, include_entity=True), created
Beispiel #10
0
 def put(self, request, *args, **kwargs):
     return ResourceResponse(self._put(request, *args, **kwargs))
Beispiel #11
0
 def post(self, request, *args, **kwargs):
     return ResourceResponse(self.create_obj(request, *args,
                                             **kwargs)), True
Beispiel #12
0
 def head(self, request, *args, **kwargs):
     return ResourceResponse(self._head(request, *args, **kwargs))
Beispiel #13
0
 def put(self, request, *args, **kwargs):
     cake, created = self._put(request, *args, **kwargs)
     return ResourceResponse(cake), created
Beispiel #14
0
 def post(self, request, *args, **kwargs):
     return ResourceResponse(self.create_obj(request, *args, **kwargs),
                             include_entity=True), True