Attribute Resolotion

More info about how attribute resolution works coming soon...

Class Reference

class canary.resolver.Resolver(*objects)

A class to handle the magic of finding attributes given as arguments to columns and filters.

To use, simply instantiate the class, handing over all objects on which you want to search for the attribute, in order of preference. Then call resolve, passing the attribute and (optionally) a default value to return if the attribute was not found.

Example:
value = Resolver(obj, view).resolve(‘get_absolute_url’, ‘’)
resolve(attr, default=None)

Resolve the given attribute from the available objects.

Args:
attr: The attribute that you want to find. default: A default value, to be used if the attribute isn’t found.
Returns:
The resolved attribute (or results of calling a method) or default.
resolve_callable(attr)

Before returning a found attribute, check if it is a method, and handle appropriately.

Args:
attr: The found attribute.
Returns:

If the attribute is a method, return the results of calling the method.

If the attribute is a view method, return the results of calling the method (passing the QuerySet object). Note: This relies on the QuerySet having been provided to the class upon instantiation.

resolve_dict(attr, default)

Resolve a dictionary.

Args:
attr: The dictionary to be resolved.
Returns:
A copy of the dictionary, with all values resolved.
resolve_list(attr, default)

Resolve a list.

Args:
attr: The list to be resolved.
Returns:
A copy of the list, with all values resolved.
resolve_string(attr, default=None)

Resolve a string.

Args:
attr: A string believed to be an attribute on one of the available
objects.

default: A value to return if the attribute can’t be resolved.

Returns:

The attribute value or the results of calling an attribute that is a method.

If those fail, return default or None.

resolve_tuple(attr, default)

Resolve a tuple.

Args:
attr: The tuple to be resolved.
Returns:
A copy of the tuple, with all values resolved.

Project Versions

Table Of Contents

Previous topic

Sorts

Next topic

Questions I Think You’ll Ask

This Page