Ticket #6043: newforms_forms.py.2.diff

File newforms_forms.py.2.diff, 2.0 KB (added by james.utter@…, 8 years ago)

adds as_ul and as_p methods

  • newforms/forms.py

     
    141141                    help_text = help_text_html % force_unicode(field.help_text)
    142142                else:
    143143                    help_text = u''
    144                 output.append(normal_row % {'errors': force_unicode(bf_errors), 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text})
     144                output.append(normal_row % {'errors': force_unicode(bf_errors), 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text, 'required': field.required and '<span class="required"> * </span>' or ''})
    145145        if top_errors:
    146146            output.insert(0, error_row % top_errors)
    147147        if hidden_fields: # Insert any hidden fields in the last row.
     
    156156
    157157    def as_table(self):
    158158        "Returns this form rendered as HTML <tr>s -- excluding the <table></table>."
    159         return self._html_output(u'<tr><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', u'<br />%s', False)
     159        return self._html_output(u'<tr><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s%(required)s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', u'<br />%s', False)
    160160
    161161    def as_ul(self):
    162162        "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>."
    163         return self._html_output(u'<li>%(errors)s%(label)s %(field)s%(help_text)s</li>', u'<li>%s</li>', '</li>', u' %s', False)
     163        return self._html_output(u'<li>%(errors)s%(label)s %(field)s%(help_text)s%(required)s</li>', u'<li>%s</li>', '</li>', u' %s', False)
    164164
    165165    def as_p(self):
    166166        "Returns this form rendered as HTML <p>s."
    167         return self._html_output(u'<p>%(label)s %(field)s%(help_text)s</p>', u'%s', '</p>', u' %s', True)
     167        return self._html_output(u'<p>%(label)s %(field)s%(help_text)s%(required)s</p>', u'%s', '</p>', u' %s', True)
    168168
    169169    def non_field_errors(self):
    170170        """
Back to Top