Example #1
0
 def __call__(self):
     displayMaxWidth = self.displayMaxWidth or 0
     hidden = renderElement(self.tag,
                            type='hidden',
                            name=self.name + ".used",
                            id=self.name + ".used",
                            value="")
     if displayMaxWidth > 0:
         elem = renderElement(self.tag,
                              type=self.type,
                              name=self.name,
                              id=self.name,
                              cssClass=self.cssClass,
                              size=self.displayWidth,
                              maxlength=displayMaxWidth,
                              extra=self.extra)
     else:
         elem = renderElement(self.tag,
                              type=self.type,
                              name=self.name,
                              id=self.name,
                              cssClass=self.cssClass,
                              size=self.displayWidth,
                              extra=self.extra)
     return "%s %s" % (hidden, elem)
Example #2
0
 def _renderItem(self, index, text, value, name, cssClass, checked=False):
     kw = {}
     if checked:
         kw['checked'] = 'checked'
     id = '%s.%s' % (name, index)
     elem = renderElement('input',
                          type="checkbox",
                          cssClass=cssClass,
                          name=name,
                          id=id,
                          value=value,
                          **kw)
     contents = self._joinButtonToMessageTemplate % (elem, text)
     return renderElement(u'label', contents=contents, **{'for': id})
Example #3
0
 def _renderItem(self, index, text, value, name, cssClass, checked=False):
     kw = {}
     if checked:
         kw['checked'] = 'checked'
     id = '%s.%s' % (name, index)
     elem = renderElement(u'input',
                          value=value,
                          name=name,
                          id=id,
                          cssClass=cssClass,
                          type='radio',
                          **kw)
     return renderElement(u'label',
                          contents='%s %s' % (elem, text),
                          **{'for': id})
Example #4
0
 def renderSelectedItem(self, index, text, value, name, cssClass):
     """Render an item for a particular `value` that is selected."""
     return renderElement('option',
                          contents=escape(text),
                          value=value,
                          cssClass=cssClass,
                          selected='selected')
Example #5
0
    def __call__(self):
        # get the data to display:
        if self._renderedValueSet():
            data = self._data
        else:
            data = self.context.get(self.context.context)

        # deal with special cases:
        if data == self.context.missing_value:
            return translate(self._missingValueMessage, self.request)
        data = list(data)
        if not data:
            return translate(self._emptySequenceMessage, self.request)

        parts = []
        for i, item in enumerate(data):
            widget = self._getWidget(i)
            widget.setRenderedValue(item)
            s = widget()
            if self.itemTag:
                s = "<%s>%s</%s>" % (self.itemTag, s, self.itemTag)
            parts.append(s)
        contents = "\n".join(parts)
        if self.tag:
            contents = "\n%s\n" % contents
            contents = renderElement(self.tag,
                                     cssClass=self.cssClass,
                                     extra=self.extra,
                                     contents=contents)
        return contents
Example #6
0
 def _div(self, cssClass, contents, **kw):
     """Render a simple div tag."""
     if contents:
         return renderElement('div',
                              cssClass=cssClass,
                              contents="\n%s\n" % contents,
                              **kw)
     return ""
Example #7
0
 def renderValue(self, value):
     rendered_items = self.renderItems(value)
     contents = "\n%s\n" % "\n".join(rendered_items)
     return renderElement('select',
                          name=self.name,
                          id=self.name,
                          contents=contents,
                          size=self.size,
                          extra=self.extra)
Example #8
0
 def __call__(self):
     return renderElement("textarea",
                          name=self.name,
                          id=self.name,
                          cssClass=self.cssClass,
                          rows=self.height,
                          cols=self.width,
                          style=self.style,
                          contents=escape(self._getFormValue()),
                          extra=self.extra)
Example #9
0
 def renderValue(self, value):
     # All we really add here is the ':list' in the name argument
     # and mutliple='multiple' to renderElement().
     rendered_items = self.renderItems(value)
     return renderElement(self.tag,
                          name=self.name + ':list',
                          id=self.name,
                          multiple='multiple',
                          size=self.size,
                          contents="\n".join(rendered_items),
                          extra=self.extra)
Example #10
0
 def hidden(self):
     items = []
     for item in self._getFormValue():
         items.append(
             renderElement(u'input',
                           type='hidden',
                           name=self.name + ':list',
                           id=self.name,
                           value=self.vocabulary.getTerm(item).token,
                           cssClass=self.cssClass,
                           extra=self.extra))
     return '\n'.join(items)
Example #11
0
 def __call__(self):
     """See IBrowserWidget."""
     value = self._getFormValue()
     if value:
         rendered_items = self.renderItems(value)
         return renderElement(self.tag,
                              id=self.name,
                              cssClass=self.cssClass,
                              contents="\n".join(rendered_items),
                              extra=self.extra)
     else:
         return self.translate(self._messageNoValue)
Example #12
0
 def __call__(self):
     if self._renderedValueSet():
         content = self._data
     else:
         content = self.context.default
     if content == self.context.missing_value:
         return ""
     formatter = self.request.locale.dates.getFormatter(
         self._category, (self.displayStyle or None))
     content = formatter.format(content)
     return renderElement("span",
                          contents=escape(content),
                          cssClass=self.cssClass)
Example #13
0
 def __call__(self):
     if self._renderedValueSet():
         content = self._data
     else:
         content = self.context.default
     if not content:
         # If there is no content it is not useful to render an anchor.
         return ''
     content = escape(content)
     kw = dict(contents=content, href=content)
     if self.linkTarget:
         kw["target"] = self.linkTarget
     return renderElement("a", **kw)
Example #14
0
 def __call__(self):
     """Render the widget to HTML."""
     value = self._getFormValue()
     if value == 'on':
         kw = {'checked': 'checked'}
     else:
         kw = {}
     return "%s %s" % (
         renderElement(self.tag,
                       type='hidden',
                       name=self.name + ".used",
                       id=self.name + ".used",
                       value=""),
         renderElement(self.tag,
                       type=self.type,
                       name=self.name,
                       id=self.name,
                       cssClass=self.cssClass,
                       extra=self.extra,
                       value="on",
                       **kw),
     )
Example #15
0
 def __call__(self):
     displayMaxWidth = self.displayMaxWidth or 0
     if displayMaxWidth > 0:
         return renderElement(self.tag,
                              type=self.type,
                              name=self.name,
                              id=self.name,
                              value='',
                              cssClass=self.cssClass,
                              style=self.style,
                              size=self.displayWidth,
                              maxlength=displayMaxWidth,
                              extra=self.extra)
     else:
         return renderElement(self.tag,
                              type=self.type,
                              name=self.name,
                              id=self.name,
                              value='',
                              cssClass=self.cssClass,
                              style=self.style,
                              size=self.displayWidth,
                              extra=self.extra)
Example #16
0
 def renderItems(self, value):
     """Render items of sequence."""
     items = []
     cssClass = self.cssClass or ''
     if cssClass:
         cssClass += "-item"
     tag = self.itemTag
     for item in value:
         term = self.vocabulary.getTerm(item)
         items.append(
             renderElement(tag,
                           cssClass=cssClass,
                           contents=escape(self.textForValue(term))))
     return items
Example #17
0
 def hidden(self):
     #XXX: _getFormValue() should return a string value that can be
     #     used in a HTML form, but it doesn't. When
     #     http://www.zope.org/Collectors/Zope3-dev/584 gets fixed
     #     this hack should be reverted.
     #     -- Bjorn Tillenius, 2006-04-12
     value = self._getFormValue()
     if value == self._missing:
         form_value = ''
     else:
         form_value = self.vocabulary.getTerm(value).token
     return renderElement(u'input',
                          type='hidden',
                          name=self.name,
                          id=self.name,
                          value=form_value,
                          cssClass=self.cssClass,
                          extra=self.extra)
Example #18
0
    def __call__(self):
        value = self._getFormValue()
        if value is None or value == self.context.missing_value:
            value = ''

        kwargs = {
            'type': self.type,
            'name': self.name,
            'id': self.name,
            'value': value,
            'cssClass': self.cssClass,
            'style': self.style,
            'size': self.displayWidth,
            'extra': self.extra
        }
        if self.displayMaxWidth:
            kwargs[
                'maxlength'] = self.displayMaxWidth  # TODO This is untested.

        return renderElement(self.tag, **kwargs)
Example #19
0
 def __call__(self):
     if self._renderedValueSet():
         content = self._data
     else:
         content = self.context.default
     return renderElement("pre", contents=escape(content))
Example #20
0
 def renderItem(self, index, text, value, name, cssClass):
     """Render an item for a particular `value`."""
     return renderElement('option',
                          contents=escape(text),
                          value=value,
                          cssClass=cssClass)