Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for a very small refactor of RestResource in rest.py. #90

Closed
rammie opened this issue Aug 2, 2013 · 2 comments
Closed

Proposal for a very small refactor of RestResource in rest.py. #90

rammie opened this issue Aug 2, 2013 · 2 comments

Comments

@rammie
Copy link

rammie commented Aug 2, 2013

It's somewhat difficult to inject custom behavior into the POST and PUT behavior for the RestResource class. The following change might make it easier to do so:
Here are the lines atop the create and edit functions in RestResource:

data = request.data or request.form.get('data') or ''
try:
    data = json.loads(data)
except ValueError:
    return self.response_bad_request()

If these were moved to a separate function and then the data passed to the create and edit functions, it would allow injection of custom behavior based on query params. The custom params could then be popped out of the data dict by the overriding function before calling super to keep the serialization working.

@rammie
Copy link
Author

rammie commented Aug 2, 2013

It may also need the bad response to be handled as an exception which is caught a few levels up. If you like the idea, I can put together a pull request.

@coleifer
Copy link
Owner

coleifer commented Oct 7, 2013

Good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants