Python wtforms.widgets.HTMLString() Examples
The following are 13
code examples of wtforms.widgets.HTMLString().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
wtforms.widgets
, or try the search function
.
Example #1
Source File: forms.py From mma-dexter with Apache License 2.0 | 6 votes |
def __call__(self, field, **kwargs): 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, inner_val == field.data)) html.append('</optgroup>') else: val = item1 label = item2 html.append(self.render_option(val, label, val == field.data)) html.append('</select>') return HTMLString(''.join(html))
Example #2
Source File: core.py From jbox with MIT License | 5 votes |
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))
Example #3
Source File: models.py From Flask-Framework-Cookbook-Second-Edition with MIT License | 5 votes |
def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) html = [] for val, label, selected in field.iter_choices(): html.append( '<input type="radio" %s> %s' % ( html_params( name=field.name, value=val, checked=selected, **kwargs ), label ) ) return HTMLString(' '.join(html))
Example #4
Source File: models.py From Flask-Framework-Cookbook-Second-Edition with MIT License | 5 votes |
def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) html = [] for val, label, selected in field.iter_choices(): html.append( '<input type="radio" %s> %s' % ( html_params( name=field.name, value=val, checked=selected, **kwargs ), label ) ) return HTMLString(' '.join(html))
Example #5
Source File: models.py From Flask-Framework-Cookbook-Second-Edition with MIT License | 5 votes |
def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) html = [] for val, label, selected in field.iter_choices(): html.append( '<input type="radio" %s> %s' % ( html_params( name=field.name, value=val, checked=selected, **kwargs ), label ) ) return HTMLString(' '.join(html))
Example #6
Source File: models.py From Flask-Framework-Cookbook-Second-Edition with MIT License | 5 votes |
def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) html = [] for val, label, selected in field.iter_choices(): html.append( '<input type="radio" %s> %s' % ( html_params( name=field.name, value=val, checked=selected, **kwargs ), label ) ) return HTMLString(' '.join(html))
Example #7
Source File: models.py From Flask-Framework-Cookbook-Second-Edition with MIT License | 5 votes |
def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) html = [] for val, label, selected in field.iter_choices(): html.append( '<input type="radio" %s> %s' % ( html_params( name=field.name, value=val, checked=selected, **kwargs ), label ) ) return HTMLString(' '.join(html))
Example #8
Source File: core.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
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))
Example #9
Source File: core.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
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))
Example #10
Source File: formatter.py From betterlifepsi with MIT License | 5 votes |
def rich_text_formatter(view, context, model, name): from wtforms.widgets import HTMLString value = getattr(model, name) return HTMLString(value)
Example #11
Source File: image_field.py From betterlifepsi with MIT License | 5 votes |
def images_formatter(view, context, model, name): from flask import render_template from wtforms.widgets import HTMLString val = getattr(model, name) return HTMLString(render_template("components/images_display.html", associated_images=val))
Example #12
Source File: forms.py From koschei with GNU General Public License v2.0 | 5 votes |
def __call__(self, **kwargs): marker = '<input type="hidden" name="{name}__present" value="1"/>'\ .format(name=self.name) return HTMLString(self.meta.render_field(self, kwargs) + marker)
Example #13
Source File: groupedselectfield.py From radremedy with Mozilla Public License 2.0 | 4 votes |
def render_option(cls, value, label, mixed): """ Renders an option as the appropriate element, but wraps options into an ``optgroup`` tag if the ``label`` parameter is ``list`` or ``tuple``. The last option, mixed, differs from "selected" in that it is a tuple containing the coercion function, the current field data, and a flag indicating if the associated field supports multiple selections. """ # See if this label is actually a group of items if isinstance(label, (list, tuple)): children = [] # Iterate on options for the children. for item_value, item_label in label: item_html = cls.render_option(item_value, item_label, mixed) children.append(item_html) html = u'<optgroup %s>%s</optgroup>\n' data = (html_params(label=unicode(value)), u''.join(children)) else: # Get our coercion function, the field data, and # a flag indicating if this is a multi-select from the tuple coerce_func, fielddata, multiple = mixed # See if we have field data - if not, don't bother # to see if something's selected. if fielddata is not None: # If this is a multi-select, look for the value # in the data array. Otherwise, look for an exact # value match. if multiple: selected = coerce_func(value) in fielddata else: selected = coerce_func(value) == fielddata else: selected = False options = {'value': value} if selected: options['selected'] = True html = u'<option %s>%s</option>\n' data = (html_params(**options), escape(unicode(label))) return HTMLString(html % data)