def __call__(self, request, **kwargs):
        self._start_time = time.time()
        self.__parse_account(request)

        self.message = None
        
        response = HttpResponseServerError('Unreachable response')
        
        
        authorize_response = self.validate_request(request)

        if authorize_response:
            response = authorize_response
        else:
            try:
                response = self.dispatch(request, self, **kwargs)
            except HttpMethodNotAllowed:
                response = HttpResponseNotAllowed(self.permitted_methods)
                response.mimetype = self.mimetype
            except Http404:
                response = HttpResponseNotFound()
            except Exception:
                self.logger.exception('Unexpected error while processing request')
                self.error_logger.exception('Unexpected error while processing request')
                response = HttpResponseServerError('Unexpected error')
        elapsed_time = time.time() - self._start_time
        
        if self.message is None:
            self.message = response.content[:120]
            
        self.executing = False
        self.logger.info('[%d] in %.3fs for [%s %s] : %s', response.status_code, elapsed_time, request.method, request.path, self.message)
        self.executing = True
        return response
예제 #2
0
    def __call__(self, request, **kwargs):
        self._start_time = time.time()
        self.__parse_account(request)

        self.message = None

        response = HttpResponseServerError('Unreachable response')

        authorize_response = self.validate_request(request)

        if authorize_response:
            response = authorize_response
        else:
            try:
                response = self.dispatch(request, self, **kwargs)
            except HttpMethodNotAllowed:
                response = HttpResponseNotAllowed(self.permitted_methods)
                response.mimetype = self.mimetype
            except Http404:
                response = HttpResponseNotFound()
            except Exception:
                self.logger.exception(
                    'Unexpected error while processing request')
                self.error_logger.exception(
                    'Unexpected error while processing request')
                response = HttpResponseServerError('Unexpected error')
        elapsed_time = time.time() - self._start_time

        if self.message is None:
            self.message = response.content[:120]

        self.executing = False
        self.logger.info('[%d] in %.3fs for [%s %s] : %s',
                         response.status_code, elapsed_time, request.method,
                         request.path, self.message)
        self.executing = True
        return response