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})
def __call__(self): """Render the widget to HTML.""" value = self._getFormValue() html = "<label for='%s'>%s" % (self.name, translate(self.context.title, context=self.request)) if self.__required: # Use the numeric character reference here instead of to make # our xml-parsing tests happier. html += " <span class='required' title='%s'> </span>" % ( translate(_(u"title_required", default="Required"), context=self.request) ) if self.context.description: html += " <span class='formHelp'>%s</span>" % translate(self.context.description, context=self.request) html += "</label>\n" if value == "on": kw = {"checked": "checked"} else: kw = {} if self.disabled: kw["disabled"] = "disabled" return "%s %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 ), html, )
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)
def renderItem(self, index, text, value, name, cssClass): id = "%s.%s" % (name, index) elem = renderElement("input", type="checkbox", cssClass=cssClass, name=name, id=id, value=value) label = renderElement("label", extra=u"for=%s" % id, contents=text) return self._joinButtonToMessageTemplate % (elem, label)
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)
def __call__(self): """Render the widget to HTML.""" value = self._getFormValue() html = "<label for='%s'>%s" % (self.name, translate(self.context.title, context=self.request)) if self.__required: # Use the numeric character reference here instead of to make # our xml-parsing tests happier. html += " <span class='required' title='%s'> </span>" % (translate(_(u'title_required', default='Required'), context=self.request)) if self.context.description: html += " <span class='formHelp'>%s</span>" % translate(self.context.description, context=self.request) html += "</label>\n" if value == 'on': kw = {'checked': 'checked'} else: kw = {} if self.disabled: kw['disabled'] = 'disabled' return "%s %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), html )
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, escape(text)) return renderElement(u"label", contents=contents, **{"for": id})
def __call__(self): button_el = widget.renderElement("span", contents=" ", id="advanced_options_button") advanced_input = widget.renderElement("input", name="advanced", value="true", contents=" ", hidden="true") return "%s<br/>%s" %(super(SearchTextWidget, self).__call__(), widget.renderElement("a", contents="%s%s%s" %(button_el, advanced_input, _("advanced options")), id="show_advanced_options", href="javascript:;") )
def _data(self, item, i, l): super(Viewlet, self)._data(item, i, l) if 'url' in item and item['url']: if not 'wysiwyg' in item: item['wysiwyg'] = '' item['wysiwyg'] += renderElement('p', contents=renderElement('a', href=item['url'], cssClass='button read-more', contents=translate(_(u'Read more'), context=self.request))) item['url'] = None
def renderItem(self, index, text, value, name, cssClass): id = '%s.%s' % (name, index) elem = renderElement('input', type="checkbox", cssClass=cssClass, name=name, id=id, value=value) label = renderElement('label', extra=u"for=%s" % id, contents=text) return self._joinButtonToMessageTemplate % (elem, label)
def __call__(self): dbitem_field = self.context bugtask = dbitem_field.context if self._renderedValueSet(): dbitem = self._data else: dbitem = dbitem_field.get(bugtask) if dbitem: return renderElement( 'span', contents=dbitem.title, cssClass="%s%s" % (dbitem_field.__name__, dbitem.name)) else: return renderElement('span', contents='—')
def __call__(self): dbitem_field = self.context bugtask = dbitem_field.context if self._renderedValueSet(): dbitem = self._data else: dbitem = dbitem_field.get(bugtask) if dbitem: return renderElement('span', contents=dbitem.title, cssClass="%s%s" % (dbitem_field.__name__, dbitem.name)) else: return renderElement('span', contents='—')
def renderItem(self, index, text, value, name, cssClass): id = '{0}.{1}'.format(name, index) elem = renderElement('input', type="checkbox", cssClass=cssClass, name=name, id=id, value=value) label = renderElement('label', extra=u'for={0}'.format(id), contents=text) return self._joinButtonToMessageTemplate.format(elem, label)
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})
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, escape(text)) return renderElement(u'label', contents=contents, **{'for': id})
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')
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
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})
def __call__(self): res = u'' value = self._getFormValue() if value is None or value == self.context.missing_value: value = [] if isinstance(value, (str, unicode)): value = value.split(self.context.delimiter) for cell in range(0, self.context.cells): kwargs = {'type': self.type, 'name': self.name, 'id': self.name + '%s' % cell, 'value': value[cell] if len(value) > cell else u'', 'cssClass': self.cssClass, 'style': self.style, 'size': self.displayWidth, 'extra': self.extra } if self.displayMaxWidth: kwargs['maxlength'] = self.displayMaxWidth if cell: res += u' → ' res += renderElement(self.tag, **kwargs) return res
def __call__(self): area = super(ProposeTextWidget, self).__call__() choice = self.choice() attr = {'name':self.name, 'id':self.name, 'cssClass': 'propose-widget' + self.cssClass, 'contents':area + choice} return renderElement('div', **attr)
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 ""
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)
def renderItem(self, index, text, value, name, cssClass): id = '%s.%s' % (name, index) el = renderElement('input', type="checkbox", cssClass=cssClass, name=name, id=id, value=value) return self._joinButtonToMessageTemplate % (cssClass, el, text, value)
def renderValue(self, value): """Render the widget with the selected value. The original renderValue separates the items with either ' ' or '<br />' which isn't suitable for us. """ rendered_items = self.renderItems(value) return renderElement( 'table', cssClass=self.cssClass, contents='\n'.join(rendered_items))
def __call__(self): assignee_field = self.context bugtask = assignee_field.context if self._renderedValueSet(): assignee = self._data else: assignee = assignee_field.get(bugtask) if assignee: person_img = renderElement( 'img', style="padding-bottom: 2px", src="/@@/person", alt="") return renderElement( 'a', href=canonical_url(assignee), contents="%s %s" % ( person_img, html_escape(assignee.displayname))) else: if bugtask.pillar.official_malone: return renderElement('i', contents='not assigned') else: return renderElement('i', contents='unknown')
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)
def renderValue(self, value): """Render the widget with the selected value. The original renderValue separates the items with either ' ' or '<br />' which isn't suitable for us. """ rendered_items = self.renderItems(value) return renderElement('table', cssClass=self.cssClass, contents='\n'.join(rendered_items))
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)
def __call__(self): """Render the widget to HTML.""" value = self._getFormValue() html = u"<label for='{0}'>{1}".format( self.name, translate(self.context.title, context=self.request) ) if self.__required: # Use the numeric character reference here instead of to make # our xml-parsing tests happier. html += u" <span class='required' title='{0}'> </span>".format( translate(_(u'title_required', default='Required'), context=self.request) ) if self.context.description: html += u" <span class='formHelp'>{0}</span>".format( translate(self.context.description, context=self.request) ) html += u"</label>\n" if value == 'on': kw = {'checked': 'checked'} else: kw = {} if self.disabled: kw['disabled'] = 'disabled' return u'{0} {1} {2}'.format( 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), html )
def renderItem(self, index, text, value, name, cssClass): """Render an item of the list.""" text = html_escape(text) id = '%s.%s' % (name, index) elem = renderElement(u'input', value=value, name=name, id=id, cssClass=cssClass, type='radio') return self._renderRow(text, value, id, elem)
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
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)
def __call__(self): if self._renderedValueSet(): content = self._data else: content = self.context.default if content == self.context.missing_value: return "" content = str(content) return renderElement("span", contents=escape(content), cssClass=self.cssClass)
def setUpOptions(self): """Set up options to be rendered.""" self.options = {} for option in ["primary", "ppa"]: attributes = dict( type="radio", name=self.name, value=option, id="%s.option.%s" % (self.name, option)) if (self.default_option is not None and self.request.form_ng.getOne( self.name, self.default_option) == option): attributes["checked"] = "checked" self.options[option] = renderElement("input", **attributes)
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)
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)
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)
def _renderItem(self, index, text, value, name, cssClass, checked=False): """Render a checkbox and text without without label.""" kw = {} if checked: kw['checked'] = 'checked' value = html_escape(value) text = html_escape(text) id = '%s.%s' % (name, index) element = renderElement( u'input', value=value, name=name, id=id, cssClass=cssClass, type='checkbox', **kw) return self._joinButtonToMessageTemplate % (element, text)
def __call__(self): attr = {'name':self.name, 'id':self.name, 'cssClass':'ui-codemirror %s' % self.cssClass, 'rows':self.height, 'cols':self.width, 'style':self.style, 'data-mode':self.context.mode, 'contents':escape(self._getFormValue()), 'extra':self.extra} return renderElement('code', **attr)
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)
def __call__(self): assignee_field = self.context bugtask = assignee_field.context if self._renderedValueSet(): assignee = self._data else: assignee = assignee_field.get(bugtask) if assignee: person_img = renderElement('img', style="padding-bottom: 2px", src="/@@/person", alt="") return renderElement( 'a', href=canonical_url(assignee), contents="%s %s" % (person_img, html_escape(assignee.displayname))) else: if bugtask.pillar.official_malone: return renderElement('i', contents='not assigned') else: return renderElement('i', contents='unknown')
def __call__(self): if self._renderedValueSet(): content = self._data else: content = self.context.default if content == self.context.missing_value: return "" content = localizeDateTime(content, self.request) formatter = self.request.locale.dates.getFormatter( self._category, (self.displayStyle or None)) content = formatter.format(content) return renderElement("span", contents=textwidgets.escape(content), cssClass=self.cssClass)
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), )
def setUpOptions(self): """Set up options to be rendered.""" self.options = {} for option in ["personal", "package", "project"]: attributes = dict(type="radio", name=self.name, value=option, id="%s.option.%s" % (self.name, option)) if self.request.form_ng.getOne(self.name, self.default_option) == option: attributes["checked"] = "checked" if self._read_only: attributes["disabled"] = "disabled" self.options[option] = renderElement("input", **attributes)
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)
def setUpOptions(self): """Set up options to be rendered.""" self.options = {} for option in ['personal', 'product']: attributes = dict(type='radio', name=self.name, value=option, id='%s.option.%s' % (self.name, option)) if self.request.form_ng.getOne(self.name, self.default_option) == option: attributes['checked'] = 'checked' self.options[option] = renderElement('input', **attributes) self.product_widget.onKeyPress = ( "selectWidget('%s.option.product', event)" % self.name)
def _renderItem(self, index, text, value, name, cssClass, checked=False): # This is an almost-complete copy of the method in Zope. We need it # to inject the style in the label, and we omit the "for" in the label # because it is redundant (and not used in legacy tests). kw = {} if checked: kw['checked'] = 'checked' value = html_escape(value) text = html_escape(text) id = '%s.%s' % (name, index) elem = renderElement(u'input', value=value, name=name, id=id, cssClass=cssClass, type='radio', **kw) if '<label' in text: return '%s %s' % (elem, text) else: return renderElement(u'label', contents='%s %s' % (elem, text), **{'style': 'font-weight: normal'})
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