Permalink
Browse files

* 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...
marinho committed May 14, 2009
1 parent 10cd7b3 commit b302f48943d5052acce53a864d0d185792f0b74a
Showing with 35 additions and 34 deletions.
  1. +7 −0 CHANGES
  2. +1 −1 geraldo/__init__.py
  3. +0 −10 geraldo/base.py
  4. +1 −1 geraldo/generators/pdf.py
  5. +24 −0 geraldo/utils.py
  6. +2 −22 geraldo/widgets.py
View
@@ -1,3 +1,10 @@
+2009-05-14: Version 0.3.0-final
+-------------------------------
+* Fixed ReportGroup.attribute_name to support methods and child attributes
+* 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
+
2009-04-30: Version 0.3.0-alpha-9
---------------------------------
* Fixed a bug on group band footer calculations when there was only one object
View
@@ -31,7 +31,7 @@
- tests - a package with automated doc tests.
"""
-VERSION = (0, 3, 0, 'alpha-9')
+VERSION = (0, 3, 0, 'final')
def get_version():
return '%d.%d.%d-%s'%VERSION
View
@@ -10,16 +10,6 @@
def landscape(page_size):
return page_size[1], page_size[0]
-def get_attr_value(obj, attr):
- """This function returns a value from a object doesn't matters if the
- attribute is a function or not"""
- value = getattr(obj, attr)
-
- if type(value) == types.MethodType:
- return value()
-
- return value
-
class BaseReport(object):
"""Basic Report class, inherited and used to make reports adn subreports"""
@@ -6,7 +6,7 @@
from reportlab.platypus import Paragraph, KeepInFrame
from reportlab.lib.units import cm
-from geraldo.base import get_attr_value
+from geraldo.utils import get_attr_value
from geraldo.widgets import Widget, Label, SystemField
from geraldo.graphics import Graphic, RoundRect, Rect, Line, Circle, Arc,\
Ellipse, Image
View
@@ -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
+
View
@@ -5,6 +5,7 @@
from reportlab.lib.colors import black
from base import BAND_WIDTH, BAND_HEIGHT, Element
+from utils import get_attr_value
class Widget(Element):
"""A widget is a value representation on the report"""
@@ -79,35 +80,14 @@ class ObjectValue(Label):
display_format = '%s'
objects = None
- def _get_part_value(self, obj, attr_path):
- """This method exists to make possible the use of an expression in
- "attribute_name" attribute.
-
- Examples:
-
- attribute_name = 'name.upper'
- attribute_name = 'customer.name'
- """
- parts = attr_path.split('.')
-
- val = getattr(obj, parts[0])
-
- if len(parts) > 1:
- val = self._get_part_value(val, '.'.join(parts[1:]))
-
- if callable(val):
- val = val()
-
- return val
-
def get_object_value(self, instance=None):
"""Return the attribute value for just an object"""
instance = instance or self.instance
if self.get_value and instance:
return self.get_value(instance)
- value = self._get_part_value(instance, self.attribute_name)
+ value = get_attr_value(instance, self.attribute_name)
# For method attributes
if type(value) == types.MethodType:

0 comments on commit b302f48

Please sign in to comment.