def internal_put(self, user=None, catalog=None, *args, **kwargs): """ Method for the developer to be able to access the endpoint internally and to get back the same results as if it was called externally. You can pass in any put params as if it was a external call by passing them into this method as KWARGS which we then will convert over into DATA for the faked put request. :user Current user who is making the request """ # create a django http request and fake # that this is a put request django_request = HttpRequest() django_request.method = 'PUT' if catalog is not None: django_request.catalog = catalog # now we convert the django http request # into a django rest framework request # and pass in the user and the kwargs request = InternalRequest(django_request, user) request._data = kwargs self.request = request try: # pass on the request and args to our put # handler and return the results return self._handle_put(request, *args) except Exception, e: self._handle_exception_for_internal(e)
def internal_get(self, user=None, catalog=None, override_pagination_url=None, override_pagination_query_params=None, *args, **kwargs): """ Method for the developer to be able to access the endpoint internally and to get back the same results as if it was called externally. You can pass in any get params as if it was a external call by passing them into this method as KWARGS which we then will convert over into url params for the faked GET request. :user Current user who is making the request """ # create a django http request and fake # that this is a get request django_request = HttpRequest() django_request.method = 'GET' django_request.GET = kwargs if catalog is not None: django_request.catalog = catalog # now we convert the django http request # into a django rest framework request # and pass in the user request = InternalRequest(django_request, user) # set the request internally to the spoofed one we just built self.request = request # check to see if the requestor wants to override the pagination url if override_pagination_url is not None: try: # parse the passed in url parsed_url = urlparse(override_pagination_url) new_query_string = '' for query_string_param in override_pagination_query_params: if query_string_param != 'page': new_query_string += '&{0}={1}'.format(query_string_param, override_pagination_query_params.get(query_string_param)) # setup the query params that were passed in self.OVERRIDDEN_PAGINATION_URL_QUERY_PARAMS = new_query_string # build out the actual url minus query params self.OVERRIDDEN_PAGINATION_URL = parsed_url.path except Exception, e: # if by any chance the parse fails we need to revert back to the api urls self.OVERRIDDEN_PAGINATION_URL_QUERY_PARAMS = None self.OVERRIDDEN_PAGINATION_URL = None
def internal_delete(self, user=None, catalog=None, *args, **kwargs): # create a django http request and fake # that this is a DELETE request django_request = HttpRequest() django_request.method = 'DELETE' if catalog is not None: django_request.catalog = catalog # now we convert the django http request # into a django rest framework request # and pass in the user and the kwargs request = InternalRequest(django_request, user) request._data = kwargs self.request = request try: # pass on the request and args to our post # handler and return the results return self._handle_delete(request, *args) except Exception, e: self._handle_exception_for_internal(e)