コード例 #1
0
    def dispatch(self, request, **kwargs):            
        """
        Handles the common operations (allowed HTTP method, authentication,
        throttling, method lookup) surrounding most CRUD interactions.
        """
        if request.method in self.methods:
            view = self.methods[request.method]
        else:
            raise NotImplementedError()
        
        raw_format, kwargs = utils.extract('__format', kwargs)
        retval = view(request, kwargs, raw_format)
        
        # views may return a status code in addition to a structured response; 
        # they may also return just a status code or just a response;
        # for true customization, we can also deal with a regular HttpResponse
        if isinstance(retval, tuple):
            raw_response, status = retval
        elif isinstance(retval, int):
            status = retval
            raw_response = {}
        elif isinstance(retval, HttpResponse):
            return retval
        else:
            raw_response = retval
            status = 200
                    
        format = self.determine_format(request, raw_format)
        return HttpResponse(self.serialize(request, raw_response, format), status=status)

        """
コード例 #2
0
    def dispatch(self, request, **kwargs):
        """
        Handles the common operations (allowed HTTP method, authentication,
        throttling, method lookup) surrounding most CRUD interactions.
        """
        if request.method in self.methods:
            view = self.methods[request.method]
        else:
            raise NotImplementedError()

        raw_format, kwargs = utils.extract("__format", kwargs)
        retval = view(request, kwargs, raw_format)

        # views may return different kinds of 'shorthand'
        # responses that we have to normalize
        raw_response, status = normalize_response(retval)

        format = self.determine_format(request, raw_format)
        return HttpResponse(self.serialize(request, raw_response, format), status=status)

        """
コード例 #3
0
    def dispatch(self, request, **kwargs):
        """
        Handles the common operations (allowed HTTP method, authentication,
        throttling, method lookup) surrounding most CRUD interactions.
        """
        if request.method in self.methods:
            view = self.methods[request.method]
        else:
            raise NotImplementedError()

        raw_format, kwargs = utils.extract('__format', kwargs)
        retval = view(request, kwargs, raw_format)

        # views may return different kinds of 'shorthand'
        # responses that we have to normalize
        raw_response, status = normalize_response(retval)

        format = self.determine_format(request, raw_format)
        return HttpResponse(self.serialize(request, raw_response, format),
                            status=status)
        """