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


Python widgets.html_params函数代码示例

本文整理汇总了Python中wtforms.widgets.html_params函数的典型用法代码示例。如果您正苦于以下问题:Python html_params函数的具体用法?Python html_params怎么用?Python html_params使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: select_multi_checkbox

def select_multi_checkbox(field, ul_class='', **kwargs):
    '''Custom multi-select widget for vendor documents needed

    Returns:
        SelectMulti checkbox widget with tooltip labels
    '''
    kwargs.setdefault('type', 'checkbox')
    field_id = kwargs.pop('id', field.id)
    html = [u'<div %s>' % widgets.html_params(id=field_id, class_=ul_class)]

    # if we don't have any field data, set it to an empty list
    # to avoid a rendering TypeError
    if field.data is None:
        field.data = []

    for value, label, _ in field.iter_choices():
        name, description, href = label
        choice_id = u'%s-%s' % (field_id, value)
        options = dict(kwargs, name=field.name, value=value, id=choice_id)
        if int(value) in field.data:
            options['checked'] = 'checked'
        html.append(u'<div class="checkbox">')
        html.append(u'<input %s /> ' % widgets.html_params(**options))
        html.append(u'<label for="%s">%s</label>' % (choice_id, build_label_tooltip(name, description)))
        html.append(u'</div>')
    html.append(u'</div>')
    return u''.join(html)
开发者ID:dobtco,项目名称:beacon,代码行数:27,代码来源:view_util.py

示例2: __call__

  def __call__(self, field, **kwargs):
    kwargs.setdefault('id', field.id)
    field_id = kwargs.pop('id')
    kwargs.setdefault('name', field.name)
    field_name = kwargs.pop('name')
    kwargs.pop('type', None)
    value = kwargs.pop('value', None)
    if value is None:
      value = field._value()
    if not value:
      value = ''

    date_fmt = kwargs.pop('format', None)
    if date_fmt is not None:
      date_fmt = date_fmt.replace("%", "")\
        .replace("d", "dd")\
        .replace("m", "mm")\
        .replace("Y", "yyyy")
    else:
      date_fmt = get_locale().date_formats['short'].pattern
      date_fmt = babel2datepicker(date_fmt)
      date_fmt = date_fmt.replace('M', 'm')  # force numerical months

    s = u'<div {}>\n'.format(html_params(
      **{'class': "input-group date",
         'data-provide': 'datepicker',
         'data-date': value,
         'data-date-format': date_fmt}))

    s += u'  <input size="13" type="text" class="form-control" {} />\n'.format(
        html_params(name=field_name, id=field_id, value=value))
    s += u'  <span class="input-group-addon"><i class="icon-calendar"></i></span>\n'
    s += u'</div>\n'
    return Markup(s)
开发者ID:mmariani,项目名称:abilian-core,代码行数:34,代码来源:widgets.py

示例3: __call__

    def __call__(self, field, **kwargs):

        if field.data:
            previous_markup = """
            <label><input {attr} /> {field.data.file_name}</label>
            """.format(
                field=field,
                attr=html_params(**{
                    'id': field.id + '-previous',
                    'class_': 'js-fileinput-previous',
                    'type': 'checkbox',
                    'name': field.name + '-previous',
                    'value': '1',
                    'checked': True,
                    'data-fileinput-new': '#{}-new'.format(field.id)
                }))

        else:
            previous_markup = ''

        upload_markup = '<input {attr} />'.format(
            attr=html_params(**{
                'id': field.id + '-new',
                'type': 'file',
                'name': field.name + '-new',
                'class_': 'file js-fileinput-new',
                'data-initial-caption': 'Upload new file...',
                'data-show-upload': 'false',
                'data-show-preview': 'false',
                'data-fileinput-previous': '#{}-previous'.format(field.id)
            }))

        markup = previous_markup + upload_markup

        return markup
开发者ID:davidmote,项目名称:occams_forms,代码行数:35,代码来源:widgets.py

示例4: __call__

 def __call__(self, field, **kwargs):
     kwargs.setdefault('id', field.id)
     html = ['<select %s>' % html_params(name=field.name, **kwargs)]
     for val, label, selected in field.iter_choices():
         html.append(self.render_option(val, label, selected))
     html.append('</select>')
     html.append('<input type=text style="display: none" {0} {1} >'
         .format(html_params(name=field.name+"_input"),
                 html_params(id=field.name+"_input")))
     return HTMLString(''.join(html))
开发者ID:peskk3am,项目名称:b2share,代码行数:10,代码来源:HTML5ModelConverter.py

示例5: __call__

 def __call__(self, field, **kwargs):
     kwargs.setdefault("id", field.id)
     name = "%s.png" % field.name
     url = kwargs.get("url", "%s/%s" % (kwargs.get("path"), name))
     kwargs.setdefault("value", name)
     preview = HTMLString(u"<img %s />" % html_params(name="preview_"+name,
                                                      src=url))
     inputButton = HTMLString(u"<input %s  />" % html_params(name=field.name,
                                                             type=u"file",
                                                             **kwargs))
     return preview + inputButton
开发者ID:linuxsoftware,项目名称:world-of-beer,代码行数:11,代码来源:form.py

示例6: select_multi_checkbox

def select_multi_checkbox(field, ul_class='', ul_role='', **kwargs):
    kwargs.setdefault('type', 'checkbox')
    field_id = kwargs.pop('id', field.id)
    html = [u'<ul %s>' % html_params(id=field_id, class_=ul_class, role=ul_role)]
    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 %s /> ' % html_params(**options))
        html.append(u'<label for="%s">%s</label></li>' % (field_id, label))
    html.append(u'</ul>')
    return u''.join(html)
开发者ID:BaxterStockman,项目名称:cloudendar,代码行数:13,代码来源:forms.py

示例7: __call__

	def __call__(self, field, **kwargs):
		kwargs.setdefault('id', field.id)
		sub_kwargs = dict((k[4:],v) for k, v in kwargs.iteritems() if k.startswith(self.sub_startswith))
		kwargs = dict(filter(lambda x: not x[0].startswith(self.sub_startswith), kwargs.iteritems()))
		sub_html = '%s %s' % (self.sub_tag, html_params(**sub_kwargs))
		html = ['<%s %s>' % (self.html_tag, html_params(**kwargs))]
		for subfield in field:
			if self.prefix_label:
				html.append('<%s>%s %s</%s>' % (sub_html, subfield.label, subfield(), self.sub_tag))
			else:
				html.append('<%s>%s %s</%s>' % (sub_html, subfield(), subfield.label, self.sub_tag))
		html.append('</%s>' % self.html_tag)
		return HTMLString(''.join(html))
开发者ID:dotajin,项目名称:haoku-open,代码行数:13,代码来源:fields.py

示例8: render_subfield

    def render_subfield(self, subfield, **kwargs):
        html = []

        html.append("<div %s>" % html_params(class_='row'))
        # Field
        html.append(subfield())
        # Buttons
        html.append("<div %s>%s</div>" % (
            html_params(class_='col-xs-2'),
            self._sort_button() + self._remove_button()
        ))
        html.append("</div>")
        return ''.join(html)
开发者ID:mhellmic,项目名称:b2share,代码行数:13,代码来源:field_widgets.py

示例9: _add_field_widget

    def _add_field_widget(field, **kwargs):
        # spoof field_name in context of it's form
        field_name = "{}{}".format(
                field._prefix,
                field.short_name,
                )

        # render child fields (which should be wrapped w/ delete widgets)
        wrapper_id = "{}_wrapper".format(field_name)
        html_string = "<div {}>".format(html_params(id=wrapper_id))
        for subfield in field:
            html_string += subfield.widget(subfield, **kwargs)
        html_string += "</div>"

        # render a hidden template of the subfields 
        template_id = "{}_template".format(field_name)
        subform_tmpl_kwargs = {
                "id": template_id,
                "style": "display: none;",
                }
        html_string += "<div {}>".format(html_params(**subform_tmpl_kwargs))
        tmpl_prefix = "{0}-!{0}!".format(field_name)
        tmpl_field = field.unbound_field.bind(form=None, name=tmpl_prefix,
                prefix="", _meta=field.meta)
        tmpl_field.process(formdata=None, data={})
        tmpl_field.widget = deleteable_widget_wrapper(tmpl_field.widget)
        html_string += tmpl_field.widget(tmpl_field)
        html_string += "</div>"

        # create function that duplicates the template field
        field_name_regex = field_name.replace("-", "\-").replace("_", "\_")
        tmpl_regex = "\!+{0}+\!".format(field_name_regex)
        onclick = """
$("#{0}").append(
    $("#{1}").clone()  // Duplicate subform from template
    .show()  // Display the duplicated subform
    .html(  // rewrite HTML of new subform
        $('#{1}').html()
            .replace(new RegExp('{2}', 'g'),
                        (new Date).getTime().toString())
         )
    .attr('id', '')  // remove #subform_template from new subform
);""".format(wrapper_id, template_id, tmpl_regex)
        new_link_params = html_params(
                href="javascript:void(0)",
                onclick=onclick,
                )
        html_string += "<a {}>".format(new_link_params)
        html_string += "New"
        html_string += "</a>"
        return HTMLString(html_string)
开发者ID:MaxwellGBrown,项目名称:notebook,代码行数:51,代码来源:dynamic_field_list.py

示例10: __call__

 def __call__(self, field, **kwargs):
     kwargs.setdefault('id', field.id)
     field_id = kwargs.pop('id')
     kwargs.pop('type', None)
     value = kwargs.pop('value', None)
     if value is None:
         value = field._value()
     if not value:
         value = ' '
     date_value, time_value = value.split(' ', 1)
     return Markup(u'<input type="date" data-datepicker="datepicker" %s /> <input type="time" data-provide="timepicker" %s />' % (
         html_params(name=field.name, id=field_id + '-date', value=date_value, **kwargs),
         html_params(name=field.name, id=field_id + '-time', value=time_value, **kwargs)
         ))
开发者ID:pajju,项目名称:baseframe,代码行数:14,代码来源:forms.py

示例11: __call__

    def __call__(self, field, **kwargs):
        kwargs.setdefault("id", field.id)
        kwargs.setdefault("name", field.name)

        template = self.data_template if field.data else self.empty_template

        return HTMLString(
            template
            % {
                "text": html_params(type="text", value=field.data),
                "file": html_params(type="file", **kwargs),
                "marker": "_%s-delete" % field.name,
            }
        )
开发者ID:dpgaspar,项目名称:Flask-AppBuilder,代码行数:14,代码来源:upload.py

示例12: __call__

 def __call__(self, field, title='', **kwargs):
     kwargs.setdefault('id', field.id)
     if self.multiple:
         kwargs['multiple'] = 'multiple'
     html = [u'<select %s>' % html_params(name=field.name, **kwargs)]
     for val, label, selected in field.iter_choices():
         options = {'value': val}
         if selected:
             options['selected'] = u'selected'            
         if val is not None or val != '_None':
             options['title'] = url('/images/flags/%s.png' % str(val))
         html.append(u'<option %s>%s</option>' % (html_params(**options), escape(unicode(label))))
     html.append(u'</select>')
     return u''.join(html)        
开发者ID:rafal-kos,项目名称:pytis,代码行数:14,代码来源:validators.py

示例13: __call__

    def __call__(self, field, **kwargs):
        kwargs.setdefault('id', field.id)
        kwargs.setdefault('name', field.name)

        template = self.data_template if field.data else self.empty_template

        return HTMLString(template % {
            'text': html_params(type='text',
                                readonly='readonly',
                                value=field.data),
            'file': html_params(type='file',
                                **kwargs),
            'marker': '_%s-delete' % field.name
        })
开发者ID:cluo,项目名称:flask-admin,代码行数:14,代码来源:upload.py

示例14: __call__

    def __call__(self, field, **kwargs):
        kwargs.setdefault('id', field.id)
        sub_kwargs = dict((k[4:], v) for k, v in kwargs.iteritems() if k.startswith(self.sub_startswith))
        kwargs = dict(filter(lambda x: not x[0].startswith(self.sub_startswith), kwargs.iteritems()))
        sub_html = '%s %s' % (self.sub_tag, html_params(**sub_kwargs))
        left = ['<%s %s>' % (self.html_tag, html_params(id='%s-left' % field.id, class_='drag-left drag-part'))]
        right = ['<%s %s>' % (self.html_tag, html_params(id='%s-right' % field.id, class_='drag-right drag-part'))]
        for subfield in field:
            if subfield.checked:
                right.append('<%s>%s %s</%s>' % (sub_html, subfield.label, subfield(), self.sub_tag))
            else:
                left.append('<%s>%s %s</%s>' % (sub_html, subfield(), subfield.label, self.sub_tag))
        left.append('</%s>' % self.html_tag)
        right.append('</%s>' % self.html_tag)
        html = """<div class="drag-select">%s%s</div><script type="text/javascript">
            $(function() {

                function initClick(id) {
                    $('#' + id + '-left > div, #' + id + 'right > div').click(function () {})
                    $('#' + id + '-left > div').unbind('click').click(function () {
                        $(this).find('input[type="checkbox"]').get(0).checked = true;
                        $('#' + id + '-right').append($(this).clone())
                        $(this).remove()
                        initClick(id);
                    })
                    $('#' + id + '-right > div').unbind('click').click(function () {
                        $(this).find('input[type="checkbox"]').removeAttr('checked');
                        $('#' + id + '-left').append($(this).clone())
                        $(this).remove()
                        initClick(id);
                    })
                }

                function init(id) {
                    dragula([document.getElementById(id + '-left'), document.getElementById(id + '-right')])
                        .on('drop', function (el, target) {
                            if (target === document.getElementById(id + '-left')) {
                                $(el).find('input[type="checkbox"]').removeAttr('checked');
                            } else {
                                $(el).find('input[type="checkbox"]').get(0).checked = true;
                            }
                            initClick(id)
                        })
                    initClick(id);
                }
                init('%s')
            });
        </script>""" % (''.join(left), ''.join(right), field.id)
        return HTMLString(html)
开发者ID:PyFansLi,项目名称:chiki,代码行数:49,代码来源:widgets.py

示例15: render_option

    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:Athlon1600,项目名称:radremedy,代码行数:49,代码来源:groupedselectfield.py


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