Tweaks to node update method

We override the update method so that the allowed_methods property can
be stripped before being sent to the server, avoiding validation issues.

We also introduce a new has_method method, which can be used in the UI
to check if the user can perform a specific method on the node.
This commit is contained in:
2015-10-12 18:24:57 +02:00
parent 33b34110a1
commit 5a856c8972

View File

@@ -31,6 +31,30 @@ class Node(List, Find, Create, Post, Update, Delete, Replace):
url = utils.join_url_params(url, params)
return cls(api.get(url))
def update(self, attributes=None, api=None):
api = api or self.api
attributes = attributes or self.to_dict()
etag = attributes['_etag']
attributes.pop('_id')
attributes.pop('_etag')
attributes.pop('_created')
attributes.pop('_updated')
attributes.pop('_links')
attributes.pop('allowed_methods')
url = utils.join_url(self.path, str(self['_id']))
headers = utils.merge_dict(
self.http_headers(),
{'If-Match': str(etag)})
new_attributes = api.put(url, attributes, headers)
self.error = None
self.merge(new_attributes)
return self.success()
def has_method(self, method):
if method in self.allowed_methods:
return True
return False
class NodeType(List, Find, Create, Post, Delete):
"""NodeType class wrapping the REST node_types endpoint