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


Python BoundField.label_tag方法代码示例

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


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

示例1: _ul_html_output

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
    def _ul_html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row):
        "Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()."
        top_errors = self.non_field_errors() # Errors that should be displayed above all fields.
        output, hidden_fields = [], []

        ##########
        ### Main hack goes like this: we want children to be rendered as <ul> *inside* parent <li>
        ### Thus, we render special tree items not as usual, but using helper atribute that sorted it as tree for us
        ##########

        for name, field in self.fields.items():
            bf = BoundField(self, field, name)
            bf_errors = self.error_class([conditional_escape(error) for error in bf.errors]) # Escape and cache in local variable.
            if bf.is_hidden:
                if bf_errors:
                    top_errors.extend([u'(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])
                hidden_fields.append(unicode(bf))
            else:
                if errors_on_separate_row and bf_errors:
                    output.append(error_row % force_unicode(bf_errors))
                if bf.label:
                    label = conditional_escape(force_unicode(bf.label))
                    # Only add the suffix if the label does not end in
                    # punctuation.
                    if self.label_suffix:
                        if label[-1] not in ':?.!':
                            label += self.label_suffix
                    label = bf.label_tag(label) or ''
                else:
                    label = ''
                if field.help_text:
                    help_text = help_text_html % force_unicode(field.help_text)
                else:
                    help_text = u''
                output.append(normal_row % {'errors': force_unicode(bf_errors), 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text})
        if top_errors:
            output.insert(0, error_row % force_unicode(top_errors))
        if hidden_fields: # Insert any hidden fields in the last row.
            str_hidden = u''.join(hidden_fields)
            if output:
                last_row = output[-1]
                # Chop off the trailing row_ender (e.g. '</td></tr>') and
                # insert the hidden fields.
                if not last_row.endswith(row_ender):
                    # This can happen in the as_p() case (and possibly others
                    # that users write): if there are only top errors, we may
                    # not be able to conscript the last row for our purposes,
                    # so insert a new, empty row.
                    last_row = normal_row % {'errors': '', 'label': '', 'field': '', 'help_text': ''}
                    output.append(last_row)
                output[-1] = last_row[:-len(row_ender)] + str_hidden + row_ender
            else:
                # If there aren't any rows in the output, just append the
                # hidden fields.
                output.append(str_hidden)
        return mark_safe(u'\n'.join(output))
开发者ID:rpgplanet,项目名称:rpghrac,代码行数:58,代码来源:forms.py

示例2: get_field_tuple

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
def get_field_tuple(name, form_or_model):
    """Returns a tuple for the field, of given instance, identified by "name".
    
    Instance could be a model instance, a form instance or any arbitrary object.
    
    The returned tuple is in the form:
    
    (label, attrs, value)
    """    
    name, sep, suffix = name.partition(':')
    
    label = ""
    value = ""
    td_attrs = {}
    field_list = get_fields(form_or_model)
    field = None
    
    if name in field_list:
        field = field_list[name]
        
    elif hasattr(form_or_model, name):
        field = getattr(form_or_model, name)
        if hasattr(field, 'short_description'):
            name = field.short_description

    if isinstance(field, models.Field):
        label = '%s:' % field.verbose_name
        value = '%s' % field_to_string(field, form_or_model)

    elif isinstance(field, forms.Field):
        bf = BoundField(form_or_model, field, name)
        label = '%s' % bf.label_tag()
        value = '%s' % bf
        if bf.help_text:
            value += '<br/><span title="%(help_text)s" class="helptext helppopup">%(help_text)s</span>' % {"help_text": '%s' % bf.help_text}
        errors = bf.errors
        if errors:
            value += '<br/>\n<ul class="errorlist">\n'
            for error in errors:
                value += '\t<li>%s</li>\n' % error
            value += '</ul>\n'
        css_classes = bf.css_classes()
        if css_classes:
            td_attrs['class'] = css_classes

    else:
        name = _(pretty_name(name).lower())
        label = '%s:' % name.capitalize()
        value = field() if callable(field) else field

    firstcap_label = label[:1].upper() + label[1:]
    if suffix:
        value += " " + suffix

    return mark_safe(firstcap_label), flatatt(td_attrs), mark_safe(value)
开发者ID:django-erp,项目名称:django-erp,代码行数:57,代码来源:models.py

示例3: uka_form_row_stacked

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
def uka_form_row_stacked(element, errors='', classes=''):
    class_margin_top = ''
    label = BoundField.label_tag(element, "", {'class': 'uk-form-label'})
    if errors:
        classes_tmp = classes + ' uk-form-danger'
        classes = classes_tmp
        class_margin_top = 'uk-margin-top'
    element = element.as_widget(attrs={'class': classes})  # to remove (be done in js)
    html_error = format_html('<div class="uk-text-danger {}">{}</div>', class_margin_top, errors)
    html = format_html(
        '<div class="uk-form-row">{}<div class="uk-form-controls">{}</div>{}</div>', label, element, html_error)
    return html
开发者ID:epi-log,项目名称:django-uikit-admin,代码行数:14,代码来源:uikit_admin.py

示例4: as_div

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
    def as_div(self):
        text_row = """<div class="form-line">%(label)s %(field)s %(errors)s %(help_text)s</div>"""
        choice_row = """<div class="form-line-choice">%(field)s %(label)s %(errors)s %(help_text)s</div>"""
        hidden_row = """<div class="form-hidden">%(field)s</div>"""
        error_row = """<div class="form-error">%s</div>"""
        help_text_html = """<div class="form-note">%s</div>"""
        required_html = """<span class="reqicon">*</span>"""

        output, hidden_fields = [], []

        for name, field in self.fields.items():
            bf = BoundField(self, field, name)
            bf_errors = self.error_class([escape(error) for error in bf.errors])

            if bf.is_hidden:
                # Just output the widget row for a hidden field
                hidden = unicode(bf).replace(u" />", u">")
                hidden_fields.append(hidden_row % {"field": hidden})
            else:
                choice_field = isinstance(field.widget, CheckboxInput)

                # Build label HTML, with required * if appropriate
                if bf.label:
                    label = escape(force_unicode(bf.label))
                    required = required_html if field.required else u""
                    label_attrs = {}
                    if choice_field:
                        label_attrs["class"] = "choice"
                    label = bf.label_tag(label + required, attrs=label_attrs) or ""
                else:
                    label = ""

                # Build help text HTML
                if field.help_text:
                    help_text = help_text_html % force_unicode(field.help_text)
                else:
                    help_text = u""

                # Output the row
                if choice_field:
                    template = choice_row
                else:
                    template = text_row
                row_context = {
                    "errors":       force_unicode(bf_errors),
                    "label":        force_unicode(label),
                    "field":        unicode(bf).replace(u" />", u">"),
                    "help_text":    help_text,
                }
                output.append(template % row_context)
        
        return mark_safe(u"\n".join(hidden_fields) + u"\n".join(output))
开发者ID:afternoon,项目名称:followize,代码行数:54,代码来源:divform.py

示例5: _html_output

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
    def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row):
        "Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()."
        top_errors = self.non_field_errors() # Errors that should be displayed above all fields.
        output, hidden_fields = [], []

        for section, fields in self.sections:
            if section:
                output.append(normal_row % {'errors': '', 'label': '&nbsp;', 'field': self.section_template%section, 'help_text': ''})

            for name, field in [i for i in self.fields.items() if i[0] in fields]:
                bf = BoundField(self, field, name)
                bf_errors = self.error_class([escape(error) for error in bf.errors]) # Escape and cache in local variable.
                if bf.is_hidden:
                    if bf_errors:
                        top_errors.extend([u'(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])
                    hidden_fields.append(unicode(bf))
                else:
                    if errors_on_separate_row and bf_errors:
                        output.append(error_row % force_unicode(bf_errors))
                    if bf.label:
                        label = escape(force_unicode(bf.label))
                        # Only add the suffix if the label does not end in
                        # punctuation.
                        if self.label_suffix:
                            if label[-1] not in ':?.!':
                                label += self.label_suffix
                        label = bf.label_tag(label) or ''
                    else:
                        label = ''
                    if field.help_text:
                        help_text = help_text_html % force_unicode(field.help_text)
                    else:
                        help_text = u''
                    output.append(normal_row % {'errors': force_unicode(bf_errors), 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text})

        if top_errors:
            output.insert(0, error_row % force_unicode(top_errors))
        if hidden_fields: # Insert any hidden fields in the last row.
            str_hidden = u''.join(hidden_fields)
            if output:
                last_row = output[-1]
                # Chop off the trailing row_ender (e.g. '</td></tr>') and
                # insert the hidden fields.
                output[-1] = last_row[:-len(row_ender)] + str_hidden + row_ender
            else:
                # If there aren't any rows in the output, just append the
                # hidden fields.
                output.append(str_hidden)
        return mark_safe(u'\n'.join(output))
开发者ID:BrianPainter,项目名称:geraldo,代码行数:51,代码来源:__init__.py

示例6: render_label

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
    def render_label(self, form):
        if isinstance(self.label, tuple):
            contents, name = self.label
        else:
            contents, name = None, self.label

        try:
            field = form.fields[name]
        except KeyError:
            return ''

        bf = BoundField(form, field, name)
        self.required = bf.field.required

        return bf.label_tag(contents)
开发者ID:hollow,项目名称:nepal,代码行数:17,代码来源:layout.py

示例7: _html_output

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
    def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row):
        # Customized to handle special case for reCaptcha forms (not rendering remote_ip field)
        "Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()."
        top_errors = self.non_field_errors() # Errors that should be displayed above all fields.
        output, hidden_fields = [], []

        for name, field in self.fields.items():
            html_class_attr = ''
            bf = BoundField(self, field, name)
            bf_errors = self.error_class([conditional_escape(error) for error in bf.errors]) # Escape and cache in local variable.
            if not bf.is_hidden:
                # Create a 'class="..."' atribute if the row should have any
                # CSS classes applied.
                css_classes = bf.css_classes()
                if css_classes:
                    html_class_attr = ' class="%s"' % css_classes

                if errors_on_separate_row and bf_errors:
                    output.append(error_row % force_unicode(bf_errors))

                if bf.label:
                    label = conditional_escape(force_unicode(bf.label))
                    # Only add the suffix if the label does not end in
                    # punctuation.
                    if self.label_suffix:
                        if label[-1] not in ':?.!':
                            label += self.label_suffix
                    label = bf.label_tag(label) or ''
                else:
                    label = ''

                if field.help_text:
                    help_text = help_text_html % force_unicode(field.help_text)
                else:
                    help_text = u''

                output.append(normal_row % {
                    'errors': force_unicode(bf_errors),
                    'label': force_unicode(label),
                    'field': unicode(bf),
                    'help_text': help_text,
                    'html_class_attr': html_class_attr
                })

        if top_errors:
            output.insert(0, error_row % force_unicode(top_errors))

        return mark_safe(u'\n'.join(output))
开发者ID:dlamotte,项目名称:django-recaptcha,代码行数:50,代码来源:forms.py

示例8: field_template

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
def field_template(name, field, form_or_model, attrs={}, suffix=""):
    label = ""
    value = ""
    output = ""
    td_attrs = {}

    if isinstance(field, models.Field):
        label = u'%s' % field.verbose_name
        value = field_to_string(field, form_or_model)

    elif isinstance(field, forms.Field):
        bf = BoundField(form_or_model, field, name)
        label = u'%s' % bf.label_tag()
        value = u'%s' % bf
        if bf.help_text:
            value += '<br/>\n<span class="help_text">%s</span>' % (u'%s' % bf.help_text)
        if bf._errors():
            value += '<br/>\n<ul class="errorlist">\n'
            for error in bf._errors():
                value += '\t<li>%s</li>\n' % error
            value += '</ul>\n'
        css_classes = bf.css_classes()
        if css_classes:
            td_attrs['class'] = css_classes

    else:
        name = _(pretty_name(name).lower())
        label = u'%s' % name.capitalize()
        if callable(field):
            value = value_to_string(field())
        else:
            value = value_to_string(field)
    
    td_attrs.update(attrs)

    if label and value:
        output += ("\t\t<th>%s</th>\n" % (label[0].capitalize() + label[1:]))
        output += "\t\t<td%s>\n" % flatatt(td_attrs)
        output += "\t\t\t%s%s\n" % (value, suffix)
        output += "\t\t</td>\n"

    return output
开发者ID:ainomugish,项目名称:prometeo-erp,代码行数:44,代码来源:details.py

示例9: bootstrapped3

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
def bootstrapped3(self):
    top_errors = self.non_field_errors()
    output, hidden_fields = [], []

    for name, field in self.fields.items():
        bf = BoundField(self, field, name)
        
        bf_errors = self.error_class([conditional_escape(error) for error in bf.errors])
        
        error_text = bf.errors.as_text()[2:]
        
        if bf.is_hidden:
            if bf_errors:
                top_errors.extend([u'(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])
            hidden_fields.append(unicode(bf))
        else:
            if bf.label:
                # Рендерялка label
                label = bf.label_tag(conditional_escape(force_unicode(bf.label)), attrs={'class': "control-label"}) or ''
            else:
                label = ''
    
            if field.help_text:
                help_text = help_text_html % force_unicode(field.help_text)
            else:
                help_text = u''
            
            self.bw_bf = bf
            self.bw_label = force_unicode(label)
            self.bw_help_text = help_text
            self.bw_css_classes = bf.css_classes()
            
            self.bw_error_text = force_unicode(error_text)
            self.bw_help_text = help_text
            
            output.append(bootstrap_widget(self, unicode(field.__class__.__name__)))
            
    return mark_safe(u'\n'.join(output))
开发者ID:sociogenetics,项目名称:xendor,代码行数:40,代码来源:forms.py

示例10: render_field

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
    def render_field(self, field):

        ''' Render a named field to HTML. '''

        try:
            field_instance = self.fields[field]
        except KeyError:
            raise NoSuchFormField("Could not resolve form field '%s'." % field)

        bf = BoundField(self, field_instance, field)

        output = ''

        bf_errors = self.error_class([escape(error) for error in bf.errors])

        if bf.is_hidden:

            # If the field is hidden, add it at the top of the form

            self.prefix_r.append(unicode(bf))

            # If the hidden field has errors, append them to the top_errors
            # list which will be printed out at the top of form

            if bf_errors:
                self.top_errors.extend(bf.errors)
        else:

            # Find field + widget type css classes
            css_class = type(field_instance).__name__ + " " + \
                        type(field_instance.widget).__name__

            # Add an extra class, Required, if applicable
            if field_instance.required:
                css_class += " Required"

            if field_instance.help_text:
                # The field has a help_text, construct <span> tag
                help_text = escape(field_instance.help_text)
                help_text = '<span class="help_text">%s</span>' % help_text

            else:
                help_text = u''

            field_hash = {'field':mark_safe(field),
                          'class':mark_safe(css_class),
                          'label':mark_safe(bf.label and bf.label_tag(bf.label) or ''),
                          'help_text':mark_safe(help_text),
                          'field':field_instance,
                          'bf':mark_safe(unicode(bf)),
                          'bf_raw':bf,
                          'errors':mark_safe(bf_errors),
                          'field_type':mark_safe(field.__class__.__name__)}

            if self.custom_fields.has_key(field):
                template = get_template(self.custom_fields[field])
            else:
                template = select_template([
                    os.path.join(self.template_base,'field_%s.html' % field_instance.__class__.__name__.lower()),
                    os.path.join(self.template_base,'field_default.html')]
                                           )

            # Finally render the field
            output = template.render(Context(field_hash))

        return mark_safe(output)
开发者ID:Matt-Sartain,项目名称:AAN,代码行数:68,代码来源:smartforms.py

示例11: render

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
    def render(self, context):
        form = context[self.arg]

        #TODO: cache
        #if adv_mode is None:
        adv_mode = Advanced.objects.order_by('-id')[0].adv_advancedmode
        #request.session['adv_mode'] = adv_mode
        form.advDefault = adv_mode

        if hasattr(form, "_meta") and hasattr(form._meta.model, '_admin'):
            model = form._meta.model
        else:
            model = None

        new_fields = form.fields.keys()
        output, hidden_fields, composed = [], [], {}

        top_errors = form.non_field_errors()
        if top_errors:
            output.append("<tr><td colspan=\"2\">%s</td></tr>" % (
                force_unicode(top_errors),
                ))
        else:
            if form.prefix:
                prefix = form.prefix + "-__all__"
            else:
                prefix = "__all__"
            output.append("""<tr>
<td colspan="2">
<input type="hidden" data-dojo-type="dijit.form.TextBox" name="%s" />
</td></tr>""" % (prefix,))

        if model:
            for label, fields in model._admin.composed_fields:
                for field in fields[1:]:
                    new_fields.remove(field)
                composed[fields[0]] = (label, fields)

        advanced_fields = getattr(form, 'advanced_fields', [])
        for field in new_fields:
            is_adv = field in advanced_fields
            _hide = ' style="display:none;"' if not adv_mode and is_adv else ''
            is_adv = ' class="advancedField"' if is_adv else ''
            if field in composed:
                label, fields = composed.get(field)
                html = u"""<tr><th><label%s>%s</label></th><td>""" % (
                    _hide,
                    label)
                for field in fields:
                    bf = BoundField(form, form.fields.get(field), field)
                    bf_errors = form.error_class(
                        [conditional_escape(error) for error in bf.errors]
                        )
                    html += unicode(bf_errors) + unicode(bf)
                html += u"</td></tr>"
                output.append(html)
            else:
                bf = BoundField(form, form.fields.get(field), field)
                bf_errors = form.error_class(
                    [conditional_escape(error) for error in bf.errors]
                    )
                if bf.is_hidden:
                    hidden_fields.append(unicode(bf))
                else:
                    if bf.help_text:
                        help_text = """<div data-dojo-type="dijit.Tooltip" data-dojo-props="connectId: '%shelp', showDelay: 200">%s</div><img id="%shelp" src="/static/images/ui/MoreInformation_16x16px.png" style="width:16px; height: 16px; cursor: help;" />""" % (bf.auto_id, bf.help_text, bf.auto_id)
                    else:
                        help_text = ""
                    html = u"""<tr%s%s><th>%s</th><td>%s%s %s</td></tr>""" % (
                        is_adv,
                        _hide,
                        bf.label_tag(),
                        bf_errors,
                        bf,
                        help_text,
                        )
                    output.append(html)

        if hidden_fields:
            str_hidden = u''.join(hidden_fields)
            output.append(str_hidden)

        return ''.join(output)
开发者ID:BillTheBest,项目名称:MetaNAS,代码行数:85,代码来源:freeadmin.py

示例12: my_html_output

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
    def my_html_output(self, normal_row, error_row, row_ender,
                       help_text_html, errors_on_separate_row, cols):
        """
        Helper function for outputting HTML.
        Used by as_table(), as_ul(), as_p().
        """
        # Errors that should be displayed above all fields.
        top_errors = self.non_field_errors()
        output, hidden_fields = [], []
        idx = 1

        for name, field in self.fields.items():
            bf = BoundField(self, field, name)
            # Escape and cache in local variable.
            bf_errors = self.error_class([conditional_escape(error)
                                         for error in bf.errors])
            if bf.is_hidden:
                if bf_errors:
                    top_errors.extend([u'(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])
                hidden_fields.append(unicode(bf))
            else:
                if errors_on_separate_row and bf_errors:
                    output.append(error_row % force_unicode(bf_errors))
                if bf.label:
                    label = conditional_escape(force_unicode(bf.label))
                    # Only add the suffix if the label does not end in
                    # punctuation.
                    if self.label_suffix:
                        if label[-1] not in ':?.!':
                            label += self.label_suffix
                    label = bf.label_tag(label) or ''
                else:
                    label = ''
                if field.help_text:
                    help_text = help_text_html % force_unicode(field.help_text)
                else:
                    help_text = u''

                normal_row2 = normal_row
                if idx == 1:
                    normal_row2 = "<tr>%s" % (normal_row,)
                elif idx >= cols:
                    idx = 0
                    normal_row2 = "%s</tr>" % (normal_row,)

                idx += 1
                output.append(normal_row2 % {
                              'errors': force_unicode(bf_errors),
                              'label': force_unicode(label),
                              'field': unicode(bf),
                              'help_text': help_text})

        if idx < cols:
            output.append("<td></td>" * (cols - idx) + "</tr>")

        if top_errors:
            output.insert(0, error_row % force_unicode(top_errors))
        if hidden_fields:  # Insert any hidden fields in the last row.
            str_hidden = u''.join(hidden_fields)
            if output:
                last_row = output[-1]
                # Chop off the trailing row_ender (e.g. '</td></tr>') and
                # insert the hidden fields.
                if not last_row.endswith(row_ender):
                    # This can happen in the as_p() case (and possibly others
                    # that users write): if there are only top errors, we may
                    # not be able to conscript the last row for our purposes,
                    # so insert a new, empty row.
                    last_row = normal_row % {
                        'errors': '',
                        'label': '',
                        'field': '',
                        'help_text': ''}
                    output.append(last_row)
                output[-1] = last_row[:-len(row_ender)] \
                    + str_hidden \
                    + row_ender
            else:
                # If there aren't any rows in the output, just append the
                # hidden fields.
                output.append(str_hidden)
        return mark_safe(u'\n'.join(output))
开发者ID:zehome,项目名称:claritick,代码行数:84,代码来源:forms.py

示例13: render_field

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
    def render_field(self, field):

        ''' Render a named field to HTML. '''

        try:
            field_instance = self.fields[field]
        except KeyError:
            raise NoSuchFormField("Could not resolve form field '%s'." % field)

        bf = BoundField(self, field_instance, field)

        output = ''

        if bf.errors:

            # If the field contains errors, render the errors to a <ul>
            # using the error_list helper function.
            bf_errors = error_list([escape(error) for error in bf.errors])

        else:
            bf_errors = ''

        if bf.is_hidden:

            # If the field is hidden, add it at the top of the form

            self.prefix.append(unicode(bf))

            # If the hidden field has errors, append them to the top_errors
            # list which will be printed out at the top of form
            
            if bf_errors:
                self.top_errors.extend(bf.errors)

        else:

            # Find field + widget type css classes
            css_class = type(field_instance).__name__ + " " + \
                        type(field_instance.widget).__name__

            # Add an extra class, Required, if applicable
            if field_instance.required:
                css_class += " Required"

            if bf.label:

                # The field has a label, construct <label> tag
                label = escape(bf.label)
                label = bf.label_tag(label) or ''

            else:
                label = ''

            if field_instance.help_text:

                # The field has a help_text, construct <span> tag
                help_text = escape(field_instance.help_text)
                help_text = '<span class="help_text">%s</span>' % help_text

            else:
                help_text = u''

            # Finally render the field
            output = '<div class="field %(class)s">%(label)s%(help_text)s%(errors)s<div class="input">%(field)s</div></div>\n' % \
                     {'class': css_class, 'label': label, 'help_text': help_text, 'errors': bf_errors, 'field': unicode(bf)}

        return output
开发者ID:akaihola,项目名称:django-wtform,代码行数:69,代码来源:forms.py

示例14: get_filters_as_options

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
 def get_filters_as_options(self):
     fields = {}
     for name, filter_ in self.filters.iteritems():
         bf = BoundField(self.form, filter_.field, name)
         fields[name] = {'label': bf.label, 'label_tag': bf.label_tag(), 'widget': bf.__unicode__(), 'filter': filter_.__class__.__name__}
     return fields
开发者ID:zaan,项目名称:django-filter,代码行数:8,代码来源:filterset.py

示例15: bootstrapped

# 需要导入模块: from django.forms.forms import BoundField [as 别名]
# 或者: from django.forms.forms.BoundField import label_tag [as 别名]
def bootstrapped(self):
    """Вывод формы отформатированной в соотвествии со стилями бутстрапа.
       Осторожно!!! Ч0рная магия и запутанный код!
    """

    normal_row = u"""
        <div class="control-group %(has_error)s">
            %(label)s
            <div class="controls">
                %(field)s
                <span class="help-inline">%(errors)s</span>
                <p class="help-block">%(help_text)s</p>
            </div>
        </div>"""
    error_row = u'<li>%s</li>'
    row_ender = u'</div>'
    help_text_html = u' %s'

    top_errors = self.non_field_errors()
    output, hidden_fields = [], []

    for name, field in self.fields.items():
        html_class_attr = ''
        
        bf = BoundField(self, field, name)
        bf_errors = self.error_class([conditional_escape(error) for error in bf.errors])
        error_text = bf.errors.as_text()[2:]
        has_error = ''
        if error_text:
            has_error = ' error'

        if bf.is_hidden:
            if bf_errors:
                top_errors.extend([u'(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])
            hidden_fields.append(unicode(bf))
        else:

            css_classes = bf.css_classes()
            if css_classes:
                html_class_attr = ' class="%s"' % css_classes

            if bf.label:
                label = conditional_escape(force_unicode(bf.label))

                if self.label_suffix:
                    if label[-1] not in ':?.!':
                        label += self.label_suffix
                label = bf.label_tag(label, attrs={'class': "control-label"}) or ''
            else:
                label = ''

            if field.help_text:
                help_text = help_text_html % force_unicode(field.help_text)
            else:
                help_text = u''
                
            output.append(normal_row % {
                'has_error': force_unicode(has_error),
                'errors': force_unicode(error_text),
                'label': force_unicode(label),
                'field': unicode(bf),
                'help_text': help_text,
                'html_class_attr': html_class_attr
            })

    if top_errors:
        output.insert(0, error_row % force_unicode(top_errors))

    if hidden_fields:
        str_hidden = u''.join(hidden_fields)
        if output:
            last_row = output[-1]

            if not last_row.endswith(row_ender):
                last_row = (normal_row % {'errors': '', 'label': '',
                                          'field': '', 'help_text':'', 'has_error': has_error,
                                          'html_class_attr': html_class_attr})
                output.append(last_row)
            output[-1] = last_row[:-len(row_ender)] + str_hidden + row_ender
        else:
            output.append(str_hidden)
    return mark_safe(u'\n'.join(output))
开发者ID:sociogenetics,项目名称:xendor,代码行数:84,代码来源:forms.py


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