Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2477 (closed enhancement: fixed)

Opened 7 years ago

Last modified 6 years ago

[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

turbogears.patch Download (1.5 KB) - added by xaka 7 years ago.

Change History

Changed 7 years ago by xaka

comment:1 Changed 7 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

comment:2 Changed 7 years ago by chrisz

  • Milestone changed from __unclassified__ to 1.1.2

comment:3 Changed 6 years ago by chrisz

  • Status changed from new to closed
  • Resolution set to fixed

The real problem here is that you don't call super in your GroupingDataGrid, and that you don't call it at the beginning of the method in ObjectPropertiesGrid. If you do that, everything works just fine. Anyway, I think the patch is omewhat reasonable, and applied it in r7167 with test in r7168.

Note: See TracTickets for help on using tickets.