def post_list(self, request, **kwargs): """ handle an incoming POST as a GET to work around URI length limitations """ # The convert_post_to_VERB() technique is borrowed from # resources.py in tastypie source. This helps us to convert the POST # to a GET in the proper way internally. request.method = 'GET' # override the incoming POST dispatch_request = convert_post_to_VERB(request, 'GET') return self.dispatch('list', dispatch_request, **kwargs)
def post_multiple(self, request, **kwargs): """ use POSTs for retrieving long lists of Signatures """ # we use the built-in Tastypie get_multiple implementation # but to do so, we need to convert the request to a GET request.method = 'GET' # override the incoming POST converted_request = convert_post_to_VERB(request, 'GET') kwarg_name = '%s_list' % self._meta.detail_uri_name kwargs[kwarg_name] = converted_request.body return self.get_multiple(converted_request, **kwargs)
def post_list(self, request, **kwargs): """ (Copied from implementation in https://github.com/greenelab/adage-server/blob/master/adage/analyze/api.py) Handle an incoming POST as a GET to work around URI length limitations """ # The convert_post_to_VERB() technique is borrowed from # resources.py in tastypie source. This helps us to convert the POST # to a GET in the proper way internally. request.method = 'GET' # override the incoming POST dispatch_request = convert_post_to_VERB(request, 'GET') return self.dispatch('list', dispatch_request, **kwargs)
def dispatch_actions(self, request, **kwargs): """ The custom actions dispatcher. Get the POST request, deserialize it, check wether the methods are allowed and return the action result. """ deserialized = self._meta.serializer.deserialize(request.raw_post_data, format="application/json") action_name = deserialized.get("action", None) if not action_name or not self.actions.mapping.get(action_name, None): raise ImmediateHttpResponse(response=http.HttpNotImplemented()) # Get only the data that are needed for further processing. new_post = QueryDict("").copy() # Make mutable QueryDict. new_post.update(deserialized.get("query", {})) new_post.update({"data": deserialized.get("data", {})}) request.POST = new_post # Get the request method out of method name and convert the request # This ensures all tastypie mechanisms will work properly request_method = action_name.split("_")[:-1] if request.method in ["get", "put", "delete", "patch"]: request = resources.convert_post_to_VERB(request, request_method.upper()) # Check wether the desired method is allowed here self.method_check(request, allowed=self._meta.allowed_methods) # Get the action method action = getattr(self, action_name, None) if action is None: raise ImmediateHttpResponse(response=http.HttpNotImplemented()) # Check all needed permissions self.is_authenticated(request) self.throttle_check(request) # At last return the method result return action(request, **kwargs)
def convert_post_to_patch(request): return convert_post_to_VERB(request, verb='PATCH')
def convert_post_to_put(request): request.body request._read_started = False return convert_post_to_VERB(request, verb='PUT')
def convert_post_to_patch(request): request.body request._read_started = False return convert_post_to_VERB(request, verb='PATCH')