Commit a998b85e authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

snf_django: Add default value to util method

Extend the 'get_attribute' method with a default value to return, in
case a non-required attribute is missing.
parent 199ad392
......@@ -120,7 +120,8 @@ def filter_modified_since(request, objects):
return objects.filter(deleted=False)
def get_attribute(request, attribute, attr_type=None, required=True):
def get_attribute(request, attribute, attr_type=None, required=True,
default=None):
value = request.get(attribute, None)
if required and value is None:
raise faults.BadRequest("Malformed request. Missing attribute '%s'." %
......@@ -129,4 +130,7 @@ def get_attribute(request, attribute, attr_type=None, required=True):
and not isinstance(value, attr_type):
raise faults.BadRequest("Malformed request. Invalid '%s' field"
% attribute)
if value is not None:
return value
else:
return default
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment