Skip to content

Commit

Permalink
Add Blueprint._decorate_view_func_or_method_view
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrech committed Sep 5, 2022
1 parent f1f8648 commit f396177
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 14 additions & 0 deletions flask_smorest/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,17 @@ def wrapper(*f_args, **f_kwargs):
return wrapper

return decorator

def _decorate_view_func_or_method_view(self, decorator, obj):
"""Apply decorator to view func or MethodView HTTP methods"""

# Decorating a MethodView decorates all HTTP methods
if isinstance(obj, type(MethodView)):
for method in self.HTTP_METHODS:
if method in obj.methods:
method_l = method.lower()
func = getattr(obj, method_l)
setattr(obj, method_l, decorator(func))
return obj

return decorator(obj)
12 changes: 1 addition & 11 deletions flask_smorest/etag.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import hashlib

from flask import request, current_app
from flask.views import MethodView

from .exceptions import PreconditionRequired, PreconditionFailed, NotModified
from .utils import deepupdate, resolve_schema_instance, get_appcontext
Expand Down Expand Up @@ -98,16 +97,7 @@ def wrapper(*args, **kwargs):

return wrapper

# Decorating a MethodView decorates all HTTP methods
if isinstance(obj, type(MethodView)):
for method in self.HTTP_METHODS:
if method in obj.methods:
method_l = method.lower()
func = getattr(obj, method_l)
setattr(obj, method_l, decorator(func))
return obj

return decorator(obj)
return self._decorate_view_func_or_method_view(decorator, obj)

@staticmethod
def _generate_etag(etag_data, extra_data=None):
Expand Down

0 comments on commit f396177

Please sign in to comment.