Get the ID of a single sub-resource

We currently have the ability to loop through all attributes on a
resource and get values which are safe to send in a request body, such
as converting the IDs of subresources. However, it would be helpful in
several cases to be able to get the ID of just one specific attribute
when overriding Resource methods. A lot of the Resources that have paths
like /images/%(image_id)/tag that need an override also need to get the
ID of the image.Image that it's set as.

Change-Id: I8d2c79ebaceb4135ab605510d009432d7d5307f3
This commit is contained in:
Brian Curtin
2015-03-11 21:21:12 -05:00
parent d0731cfc33
commit d85f6dbe02

View File

@@ -455,6 +455,14 @@ class Resource(collections.MutableMapping):
# CRUD OPERATIONS
##
@staticmethod
def _get_id(value):
"""If a value is a Resource, return the canonical ID."""
if isinstance(value, Resource):
return value.id
else:
return value
@staticmethod
def _convert_ids(attrs):
"""Return an attribute dictionary suitable for create/update