我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用wtforms.widgets.html_params()。
def render_select(cls, part, field): """Render select for a specific part of date.""" yield "<select %s>" % html_params(name=field.name + ":" + part) # If user didn't specifiy the date then the year range will start from current year + 5 years range_value = cls.__current_year + 5 try: current_value = int(getattr(field.data, part)) range_value = current_value + 5 except Exception: current_value = None # TODO: localization yield "<option %s>%s</option>" % (html_params(value="", selected=(current_value is None)), part.capitalize()) option_format = "<option %s>%04d</option>" if part == "year" else "<option %s>%02d</option>" for v in range(range_value, 1912, -1) if part == "year" else range( 1, 13 if part == "month" else 32): yield option_format % (html_params(value=v, selected=(v == current_value)), v) yield "</select>"
def __call__(self, field, **kwargs): html = [] kwargs.setdefault('id', field.id) html.append('<div %s>' % html_params(**kwargs)) hidden = '' for subfield in field: if subfield.type == 'HiddenField': hidden += text_type(subfield) else: html.append('<div><span>%s</span>%s%s</div>' % ( text_type(subfield.label), hidden, text_type(subfield))) hidden = '' html.append('</div>') if hidden: html.append(hidden) return HTMLString(''.join(html))
def select_multi_checkbox(field, ul_class='', **kwargs): kwargs.setdefault('type', 'checkbox') field_id = kwargs.pop('id', field.id) html = [u'<ul style="list-style-type: none; padding-left: 0px;" %s>' % html_params(id=field_id, class_=ul_class)] for value, label, checked in field.iter_choices(): choice_id = u'%s-%s' % (field_id, value) options = dict(kwargs, name=field.name, value=value, id=choice_id) if checked: options['checked'] = 'checked' html.append(u'<li><input style="margin-left: 0px;" %s /> ' % html_params(**options)) html.append(u'<label for="%s">%s</label></li>' % (field_id, label)) html.append(u'</ul>') return u''.join(html)
def __call__(self, text=None, **kwargs): if 'for_' in kwargs: kwargs['for'] = kwargs.pop('for_') else: kwargs.setdefault('for', self.field_id) attributes = widgets.html_params(**kwargs) return widgets.HTMLString('<label %s>%s</label>' % (attributes, text or self.text))
def __call__(self, field, **kwargs): """Render widget.""" kwargs.setdefault('id', field.id) html = ["<!-- data: %r -->" % (field.data, ), '<div %s>' % html_params(**kwargs)] html.extend(self.render_select("year", field)) html.extend(self.render_select("month", field)) html.extend(self.render_select("day", field)) html.append("</div>") return HTMLString(''.join(html))
def __call__(self, field, **kwargs): if isinstance(field.data, (list, tuple)): def compare(val): return val in field.data else: def compare(val): return val == field.data kwargs.setdefault('id', field.id) if self.multiple: kwargs['multiple'] = True html = ['<select %s>' % html_params(name=field.name, **kwargs)] for item1, item2 in field.choices: if isinstance(item2, (list, tuple)): group_label = item1 group_items = item2 html.append('<optgroup %s>' % html_params(label=group_label)) for inner_val, inner_label in group_items: html.append(self.render_option(inner_val, inner_label, compare(inner_val))) html.append('</optgroup>') else: val = item1 label = item2 html.append(self.render_option(val, label, compare(val))) html.append('</select>') return HTMLString(''.join(html))