我们从Python开源项目中,提取了以下32个代码示例,用于说明如何使用wtforms.widgets.HTMLString()。
def __call__(self, field, **kwargs): """Render table to HTML.""" columns = kwargs.pop('columns', field.columns) rows = kwargs.pop('rows', field.rows) html = [] html.append('<div class="table-responsive"><table class="table ' 'table-striped"><thead><tr><th />') for column in columns: html.append('<th>{}</th>'.format(column)) html.append('</tr></thead><tbody>') for row in rows: html.append('<tr><td><input class="form-check-input" ' 'type="checkbox" name="obj_id" value="{}" ' '/></td>'.format(row[0])) for value in row[1:]: html.append('<td>{}</td>'.format(value)) html.append('</tr>') html.append('</tbody></table></div>') return HTMLString(''.join(html))
def __call__(self, field, **kwargs): show_input = True show_preview = True if 'only_input' in kwargs or 'only_preview' in kwargs: show_input = kwargs.pop('only_input', False) show_preview = kwargs.pop('only_preview', False) if not show_input and not show_preview: raise ValueError('One of show_input and show_preview must be true') html = '' if show_input: class_ = kwargs.pop('class', '').split() + \ kwargs.pop('class_', '').split() class_ += ['flask-pagedown-input'] html += pagedown_pre_html + super(PageDown, self).__call__( field, id='flask-pagedown-' + field.name, class_=' '.join(class_), **kwargs) + pagedown_post_html if show_preview: html += preview_html % {'field': field.name} return HTMLString(html)
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 __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): html = super(PageDown, self).__call__(field, id = 'flask-pagedown-' + field.name, class_ = 'flask-pagedown-input', **kwargs) return HTMLString(pagedown_pre_html + html + pagedown_post_html % field.name)
def __call__(self, field, **kwargs): objpk = kwargs.get('pk', None) obj = kwargs.get('obj', None) kwargs.setdefault('id', field.id) if obj is not None: return HTMLString(obj.as_image) return ""
def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) kwargs.setdefault('type', self.input_type) kwargs.setdefault('value', field.id) return HTMLString('<button %s>%s</button>' % (self.html_params(name=field.name, **kwargs), field.label.text)) # Represents a <button type="submit">, allowing checking if a submit button has been pressed.
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 play_btn_formatter(self, context, model, name): btn = """ <a class="btn btn-primary pull-right" href="%s"> <span class="fa fa-play glyphicon glyphicon-play"></span> </a>""" % url_for('.run_job', pk=model.get('_id')) return HTMLString(btn)
def run_job(self, pk): #TODO: ajax call job = self.coll.find_one({'_id': ObjectId(pk)}) name = 'auto-' + job.get('name') client.build_job(name) info = client.get_job_info(name) flash(HTMLString(u'?????? "%s" ???????? <a href="%s" target="_blank">?????????</a>' % (name, info.get('url')))) return redirect(url_for('.index_view')) # TODO
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))