Ticket #2477 (closed enhancement: fixed)
[PATCH] TG Widgets: Move default value getting from adjust_value to display
| Reported by: | xaka | Owned by: | Chris Arndt |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.1.2 |
| Component: | TG Widgets | Version: | 1.1 HEAD |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Now default value getting implemented at adjust_value method level. I think that you should move it to display method and pass to adjust_value already calculated value (passed to display or default if passed was None).
Why? It will help to organize adjust_value call-chain and be more clear - no need to call parent's adjust_value to get default widget's value. We always will now that passed value is the value from display call or default.
For an example we have GroupingDataGrid? which automatically will group passed list. Widget will do it in adjust_value (i.e. it expects that you pass None or iterable object):
class GroupingDataGrid(Widget):
def adjust_value(self, value, **params):
if value:
value = self.group_by_field(value, params['group_field'])
return value
Next, we have some ObjectPropertiesGrid? which based on GroupingDataGrid?. This new widget expects object id as it's value. Widget convert passed object id to list of object properties in adjust_value and pass that list to adjust_value of GroupingDataGrid?:
class ObjectPropertiesGrid(GroupingDataGrid):
def adjust_value(self, value, **params):
if value:
objid = value
value = get_list_of_properties(value)
return super(ObjectPropertiesGrid, self).adjust_value(value, **params)
Without attached patch you can't do it because to get default widget's value you need to call parent's adjust_value or copy/paste code to get default value that is not good idea. In situation above you also can't call parent's adjust_value because it expects value for processing.
Patch is 100% compatible with old and new code. I hope you can understand my thoughts and explanation :)
---------------------------------------------------------------------- Ran 444 tests in 73.432s OK
Attachments
Change History
comment:1 Changed 2 years ago by xaka
- Summary changed from TG Widgets: Move default value getting from adjust_value to display to [PATCH] TG Widgets: Move default value getting from adjust_value to display
