def process_view(self, request, view_func, view_args, view_kwargs): '''Validates a request before it calls the appropriate processing method in the node.''' try: node_cls = view_func.im_self request = HttpRequest(request) if not len(node_cls.get_allowed_methods(implicits=False)): raise Http404 if request.method not in node_cls.get_allowed_methods(): raise MethodNotAllowedError(node_cls) if request.method != 'OPTIONS': if not len(get_matching_mime_types(request, node_cls)): raise NotAcceptableError(node_cls) except (HttpError), http_exception: return self.process_exception(request, http_exception)
def __init__(self, request, *args, **kwargs): '''Initializes a new instance of the Node class: - request: Current HttpRequest instance. - *args, **kwargs are passed all the way to the top parent node.''' self.request = request members = filter(lambda x: x not in ['self', 'request'], inspect.getargspec(self.__init__)[0]) self.__locals = dict(zip(members, args)) map(lambda t: setattr(self, t[0], t[1]), self.__locals.items()) kwargs.update(self.__locals) self._chained_args = kwargs if self.parent: self._parent_instance = self.parent(request, **self._chained_args) self._try_cross() self._matching_outputs = get_matching_mime_types( request, self.__class__)