Skip to content

Commit

Permalink
Fixed default View arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jtc42 committed Jun 29, 2020
1 parent c80e45f commit 881ee3f
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/labthings/server/view/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ def dispatch_request(self, *args, **kwargs):
if meth is None and request.method == "HEAD":
meth = getattr(self, "get", None)

# Marhal response if a response schema is defines
# Inject request arguments if an args schema is defined
if request.method in ("POST", "PUT", "PATCH") and self.get_args():
meth = use_args(self.get_args())(meth)

# Marhal response if a response schema is defined
if (
request.method in ("GET", "PUT", "POST", "PATCH", "DELETE")
request.method in ("GET", "PUT", "POST", "PATCH")
and self.get_schema()
):
meth = marshal_with(self.get_schema())(meth)
Expand Down Expand Up @@ -190,22 +194,8 @@ def get_args(cls):
return cls.schema

def dispatch_request(self, *args, **kwargs):
meth = getattr(self, request.method.lower(), None)

# If the request method is HEAD and we don't have a handler for it
# retry with GET.
if meth is None and request.method == "HEAD":
meth = getattr(self, "get", None)

# Flask should ensure this is assersion never fails
assert meth is not None, f"Unimplemented method {request.method!r}"

# Inject request arguments if an args schema is defined
if request.method in ("POST", "PUT", "PATCH") and self.get_args():
meth = use_args(self.get_args())(meth)

# Generate basic response
resp = self.represent_response(meth(*args, **kwargs))
resp = View.dispatch_request(self, *args, **kwargs)

# Emit property event
if request.method in ("POST", "PUT", "DELETE", "PATCH"):
Expand Down

0 comments on commit 881ee3f

Please sign in to comment.