Hey people,
I have a suggestion for the attrwrapper class of
turbogers.widgets.DataGrid.Column.
At the moment it is impossible to define a method as the value getter
of the value of a cell in the DataGrid.
It is possible to use DataGrid(fields=[('Name','name')]) but not
DataGrid(fields=[('Name','getname()')]) or something similar. I
defined my own DataGridMod where the attrwrapper.__call__ checks if
the attribute is callable, and if so, calls it, if not, just returns
the value of the attribute.
Now when I use fields=[('Name','name')], it doesn't matter if 'name'
is a method or an attribute.
Other modifications are just to make sure this behaviour is working
correctly.
Does anybody have any comments on this? Wouldn't it be easier to
provide this standard in turbogears?
Cheers,
Dolf.
class DataGridMod(widgets.DataGrid):
class Column(widgets.DataGrid.Column):
def __init__(self, name, getter=None, title=None,
options=None):
if not name:
raise ValueError, 'name is required'
if getter:
if callable(getter):
self.getter = getter
else: # assume it's an attribute name
self.getter = DataGridMod.attrwrapper(getter)
else:
self.getter = DataGridMod.attrwrapper(name)
self.name = name
self.title = title or name.capitalize()
self.options = options or {}
class attrwrapper:
def __init__(self, name):
self.name = name
def __call__(self,obj,args=dict()):
att=getattr(obj, self.name)
if callable(att):
att=att(**args)
return att
while the original __call__ from attrwrapper in DataGrid is:
def __call__(self, obj):
return getattr(obj, self.name)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---