Skip to content

Flask - Use as_list and as_detail in favour of as_view #112

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions restless/fl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,15 @@ class FlaskResource(Resource):
Flask environment.
"""
@classmethod
def as_list(cls, *init_args, **init_kwargs):
def as_view(cls, view_type, *init_args, **init_kwargs):
# Overridden here, because Flask uses a global ``request`` object
# rather than passing it to each view.
def _wrapper(*args, **kwargs):
# Make a new instance so that no state potentially leaks between
# instances.
inst = cls(*init_args, **init_kwargs)
inst.request = request
return inst.handle('list', *args, **kwargs)

return _wrapper

@classmethod
def as_detail(cls, *init_args, **init_kwargs):
# Overridden here, because Flask uses a global ``request`` object
# rather than passing it to each view.
def _wrapper(*args, **kwargs):
# Make a new instance so that no state potentially leaks between
# instances.
inst = cls(*init_args, **init_kwargs)
inst.request = request
return inst.handle('detail', *args, **kwargs)
return inst.handle(view_type, *args, **kwargs)

return _wrapper

Expand Down