Loaders: remove data flag from load_item_request. It is only being executed if data==True, which leads to think that it should perform the action in any case and only be called if needed (i.e. data==True should be checked by who invokes the function).
Loaders: removes load_create_request. After removing the data flag, the content of said function is identical to load_item_request.
Open questions:
The selection of loader and response handler is done in the content negotiation and it is stored in the resource_requestctx. Then this object is updated based on the result of a call to a function from its attributes... Sounds a bit wrong. Propsal:
Option 1:
Move the _response_handlers and _request_loader to the BaseView since all views seem to have it.
Create a function or decorator similar to the following. It would be called at the beginning of each method (get, post, etc.)
def _select_from_mimetype():
"""Selects the response handler and request loader based on the MIMETypes."""
self.request_loader = self._request_loaders[resource_requestctx.accept_mimetype]
self.response_handler = self._request_loaders[
resource_requestctx.payload_mimetype
]
Option 2:
Create 2 decorators:
def _select_response_handler_from_mimetype():
"""Selects the response handler based on the MIMETypes."""
self.response_handler = self._request_loaders[
resource_requestctx.payload_mimetype
]
def _select_request_loader_from_mimetype():
"""Selects the request loader based on the MIMETypes."""
self.request_loader = self._request_loaders[resource_requestctx.accept_mimetype]
Since not every function requires both loader and handler, only those that require would call them.
Requires #42 Closes https://github.com/inveniosoftware/flask-resources/issues/38
Changes:
data
flag fromload_item_request
. It is only being executed ifdata==True
, which leads to think that it should perform the action in any case and only be called if needed (i.e.data==True
should be checked by who invokes the function).load_create_request
. After removing the data flag, the content of said function is identical toload_item_request
.Open questions:
The selection of loader and response handler is done in the content negotiation and it is stored in the
resource_requestctx
. Then this object isupdate
d based on the result of a call to a function from its attributes... Sounds a bit wrong. Propsal:Option 1:
Move the
_response_handlers
and_request_loader
to theBaseView
since all views seem to have it.Create a function or decorator similar to the following. It would be called at the beginning of each method (get, post, etc.)
Option 2:
Create 2 decorators:
Since not every function requires both loader and handler, only those that require would call them.
To allow this PR to be merged, opened a different issue to tackle said problem: https://github.com/inveniosoftware/flask-resources/issues/44