-
Notifications
You must be signed in to change notification settings - Fork 72
HTTP Methods
Thomas Pollet edited this page Oct 3, 2022
·
3 revisions
You can limit the http methods that are allowd by declaring the http_methods
class attribute:
class Person(BaseModel):
http_methods = ["get"]
It is possible to customize the PATCH and POST methods of an instance by overriding the SAFRSBase
_s_patch
and _s_post
methods. For example:
def _s_patch(self, *args, **kwargs):
"""
Verify access when updating a user
"""
print(kwargs)
if g.user is self or g.user.role == "admin":
return SAFRSBase._s_patch(self, *args, **kwargs)
raise AuthorizationError("Not allowed")
The kwargs
dictionary will contain the jsonapi data.attributes
.
An _s_post
override should be a classmethod (POST
is used to create an instance so an instance does not yet exist when this method is called)
@classmethod
def _s_post(cls, *args, **kwargs):
print(kwargs)
result = cls(*args, **kwargs)
print(result)
return result