Ignore:
Timestamp:
6 Aug 2010, 08:50:03 (14 years ago)
Author:
uli
Message:

Change initialization to support different subwidgets for key and
value parts.

These two subwidgets should are respected by both the input and the
display widget.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.widgets.core/trunk/src/waeup/widgets/core/dictwidget.py

    r5368 r5375  
    4848    template = ViewPageTemplateFile('dictwidget.pt')
    4949   
    50     def __init__(self, context, request, subwidget=None):
     50    def __init__(self, context, request, key_subwidget=None,
     51                 value_subwidget=None):
    5152        super(DictWidget, self).__init__(context, None, request)
    52         self.subwidget = subwidget
     53        self.key_subwidget = key_subwidget
     54        self.value_subwidget = value_subwidget
    5355
    5456        # The subwidgets are cached in this dict if preserve_widgets is True.
     
    6971        if i not in self._widgets:
    7072            key_field = self.context.key_type
    71             if self.subwidget is not None:
    72                 key_widget = self.subwidget(key_field, self.request)
     73            if self.key_subwidget is not None:
     74                key_widget = self.key_subwidget(key_field, self.request)
    7375            else:
    7476                key_widget = getMultiAdapter(
     
    7779           
    7880            value_field = self.context.value_type
    79             if self.subwidget is not None:
    80                 value_widget = self.subwidget(value_field, self.request)
     81            if self.value_subwidget is not None:
     82                value_widget = self.value_subwidget(value_field, self.request)
    8183            else:
    8284                value_widget = getMultiAdapter(
     
    224226    extra = ""
    225227
    226     def __init__(self, context, request, subwidget=None):
     228    def __init__(self, context, request, key_subwidget=None,
     229                 value_subwidget=None):
    227230        super(DictDisplayWidget, self).__init__(context, request)
    228         self.subwidget = subwidget
     231        self.key_subwidget = key_subwidget
     232        self.value_subwidget = value_subwidget
    229233
    230234    def __call__(self):
     
    266270        key_field = self.context.key_type
    267271        value_field = self.context.value_type
    268         if self.subwidget is not None:
    269             key_widget = self.subwidget(key_field, self.request)
    270             value_widget = self.subwidget(value_field, self.request)
     272        if self.key_subwidget is not None:
     273            key_widget = self.key_subwidget(key_field, self.request)
    271274        else:
    272275            key_widget = getMultiAdapter(
    273276                (key_field, self.request), IDisplayWidget)
     277        if self.value_subwidget is not None:
     278            value_widget = self.value_subwidget(value_field, self.request)
     279        else:
    274280            value_widget = getMultiAdapter(
    275281                (value_field, self.request), IDisplayWidget)
Note: See TracChangeset for help on using the changeset viewer.