当前位置: 首页>>代码示例>>Python>>正文


Python widgets.HTMLString方法代码示例

本文整理汇总了Python中wtforms.widgets.HTMLString方法的典型用法代码示例。如果您正苦于以下问题:Python widgets.HTMLString方法的具体用法?Python widgets.HTMLString怎么用?Python widgets.HTMLString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wtforms.widgets的用法示例。


在下文中一共展示了widgets.HTMLString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: from wtforms import widgets [as 别名]
# 或者: from wtforms.widgets import HTMLString [as 别名]
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)) 
开发者ID:Code4SA,项目名称:mma-dexter,代码行数:21,代码来源:forms.py

示例2: __call__

# 需要导入模块: from wtforms import widgets [as 别名]
# 或者: from wtforms.widgets import HTMLString [as 别名]
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)) 
开发者ID:jpush,项目名称:jbox,代码行数:10,代码来源:core.py

示例3: __call__

# 需要导入模块: from wtforms import widgets [as 别名]
# 或者: from wtforms.widgets import HTMLString [as 别名]
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)) 
开发者ID:PacktPublishing,项目名称:Flask-Framework-Cookbook-Second-Edition,代码行数:14,代码来源:models.py

示例4: rich_text_formatter

# 需要导入模块: from wtforms import widgets [as 别名]
# 或者: from wtforms.widgets import HTMLString [as 别名]
def rich_text_formatter(view, context, model, name):
    from wtforms.widgets import HTMLString
    value = getattr(model, name)
    return HTMLString(value) 
开发者ID:betterlife,项目名称:betterlifepsi,代码行数:6,代码来源:formatter.py

示例5: images_formatter

# 需要导入模块: from wtforms import widgets [as 别名]
# 或者: from wtforms.widgets import HTMLString [as 别名]
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)) 
开发者ID:betterlife,项目名称:betterlifepsi,代码行数:8,代码来源:image_field.py

示例6: __call__

# 需要导入模块: from wtforms import widgets [as 别名]
# 或者: from wtforms.widgets import HTMLString [as 别名]
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) 
开发者ID:fedora-infra,项目名称:koschei,代码行数:6,代码来源:forms.py

示例7: render_option

# 需要导入模块: from wtforms import widgets [as 别名]
# 或者: from wtforms.widgets import HTMLString [as 别名]
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) 
开发者ID:radremedy,项目名称:radremedy,代码行数:51,代码来源:groupedselectfield.py


注:本文中的wtforms.widgets.HTMLString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。