Ignore:
Timestamp:
3 Apr 2012, 07:37:37 (13 years ago)
Author:
Henrik Bettermann
Message:

Use customized translations for sequence widgets.

Attention: The call method of the original SequenceDisplayWidget? had to be patched because it contains a bug (mail will follow).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/widgets/sequencewidget.py

    r7819 r8024  
    2222"""
    2323import grok
     24from zope.i18n import translate
    2425from zope.browserpage import ViewPageTemplateFile
    2526from zope.formlib.interfaces import IInputWidget, IDisplayWidget
     
    4748    itemTag = 'div'
    4849
     50    def __call__(self):
     51    """This is is a patch for the orginal __call__ method which doesn't call
     52    the translate function properly.
     53    """
     54
     55        # get the data to display:
     56        if self._renderedValueSet():
     57            data = self._data
     58        else:
     59            data = self.context.get(self.context.context)
     60
     61        # deal with special cases:
     62        if data == self.context.missing_value:
     63            return translate(self._missingValueMessage, context=self.request)
     64        data = list(data)
     65        if not data:
     66            return translate(self._emptySequenceMessage, context=self.request)
     67
     68        parts = []
     69        for i, item in enumerate(data):
     70            widget = self._getWidget(i)
     71            widget.setRenderedValue(item)
     72            s = widget()
     73            if self.itemTag:
     74                s = "<%s>%s</%s>" % (self.itemTag, s, self.itemTag)
     75            parts.append(s)
     76        contents = "\n".join(parts)
     77        if self.tag:
     78            contents = "\n%s\n" % contents
     79            contents = renderElement(self.tag,
     80                                     cssClass=self.cssClass,
     81                                     extra=self.extra,
     82                                     contents=contents)
     83        return contents
     84
    4985# Register our sequence widgets as default for lists.
    5086@grok.adapter(IList, IField, IBrowserRequest)
Note: See TracChangeset for help on using the changeset viewer.