-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed ReportGroup.attribute_name to support methods and child attri…
…butes * Created a new module 'utils.py' with once function to get attribute values from objects support methods and expression paths. It is used by ReportGroup.attribute_name and Widget.attribute_name
- Loading branch information
Showing
6 changed files
with
35 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
def get_attr_value(obj, attr_path): | ||
"""This function gets an attribute value from an object. If the attribute | ||
is a method with no arguments (or arguments with default values) it calls | ||
the method. If the expression string has a path to a child attribute, it | ||
supports. | ||
Examples: | ||
attribute_name = 'name' | ||
attribute_name = 'name.upper' | ||
attribute_name = 'customer.name.lower' | ||
""" | ||
parts = attr_path.split('.') | ||
|
||
val = getattr(obj, parts[0]) | ||
|
||
if len(parts) > 1: | ||
val = get_attr_value(val, '.'.join(parts[1:])) | ||
|
||
if callable(val): | ||
val = val() | ||
|
||
return val | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters