Don't process the AttributeError exception but let calling code handle it.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -123,36 +123,30 @@ def resolve(path, urlconf=None):
|
|||||||
|
|
||||||
|
|
||||||
def return_attrib(obj, attrib, arguments=None):
|
def return_attrib(obj, attrib, arguments=None):
|
||||||
try:
|
if isinstance(attrib, types.FunctionType):
|
||||||
if isinstance(attrib, types.FunctionType):
|
return attrib(obj)
|
||||||
return attrib(obj)
|
elif isinstance(
|
||||||
elif isinstance(
|
obj, dict_type
|
||||||
obj, dict_type
|
) or isinstance(obj, dictionary_type):
|
||||||
) or isinstance(obj, dictionary_type):
|
return obj[attrib]
|
||||||
return obj[attrib]
|
else:
|
||||||
else:
|
result = reduce_function(getattr, attrib.split('.'), obj)
|
||||||
result = reduce_function(getattr, attrib.split('.'), obj)
|
if isinstance(result, types.MethodType):
|
||||||
if isinstance(result, types.MethodType):
|
if arguments:
|
||||||
if arguments:
|
return result(**arguments)
|
||||||
return result(**arguments)
|
|
||||||
else:
|
|
||||||
return result()
|
|
||||||
else:
|
else:
|
||||||
return result
|
return result()
|
||||||
except Exception as exception:
|
|
||||||
if settings.DEBUG:
|
|
||||||
return 'Attribute error: %s; %s' % (attrib, exception)
|
|
||||||
else:
|
else:
|
||||||
return force_text(exception)
|
return result
|
||||||
|
|
||||||
|
|
||||||
def return_related(instance, attribute):
|
def return_related(instance, related_field):
|
||||||
"""
|
"""
|
||||||
This functions works in a similar method to return_attrib but is
|
This functions works in a similar method to return_attrib but is
|
||||||
meant for related models. Support multiple levels of relationship
|
meant for related models. Support multiple levels of relationship
|
||||||
using double underscore.
|
using double underscore.
|
||||||
"""
|
"""
|
||||||
return reduce_function(getattr, attribute.split('__'), instance)
|
return reduce_function(getattr, related_field.split('__'), instance)
|
||||||
|
|
||||||
|
|
||||||
def urlquote(link=None, get=None):
|
def urlquote(link=None, get=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user