~ubuntu-branches/ubuntu/jaunty/python-django/jaunty-updates

« back to all changes in this revision

Viewing changes to django/forms/forms.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2008-11-15 19:15:33 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115191533-xbt1ut2xf4fvwtvc
Tags: 1.0.1-0ubuntu1
* New upstream release:
  - Bug fixes.

* The tests/ sub-directory appaers to have been dropped upstream, so pull
  our patch to workaround the tests and modify the rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
from copy import deepcopy
6
6
 
7
7
from django.utils.datastructures import SortedDict
8
 
from django.utils.html import escape
 
8
from django.utils.html import conditional_escape
9
9
from django.utils.encoding import StrAndUnicode, smart_unicode, force_unicode
10
10
from django.utils.safestring import mark_safe
11
11
 
140
140
        output, hidden_fields = [], []
141
141
        for name, field in self.fields.items():
142
142
            bf = BoundField(self, field, name)
143
 
            bf_errors = self.error_class([escape(error) for error in bf.errors]) # Escape and cache in local variable.
 
143
            bf_errors = self.error_class([conditional_escape(error) for error in bf.errors]) # Escape and cache in local variable.
144
144
            if bf.is_hidden:
145
145
                if bf_errors:
146
146
                    top_errors.extend([u'(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])
149
149
                if errors_on_separate_row and bf_errors:
150
150
                    output.append(error_row % force_unicode(bf_errors))
151
151
                if bf.label:
152
 
                    label = escape(force_unicode(bf.label))
 
152
                    label = conditional_escape(force_unicode(bf.label))
153
153
                    # Only add the suffix if the label does not end in
154
154
                    # punctuation.
155
155
                    if self.label_suffix:
171
171
                last_row = output[-1]
172
172
                # Chop off the trailing row_ender (e.g. '</td></tr>') and
173
173
                # insert the hidden fields.
 
174
                if not last_row.endswith(row_ender):
 
175
                    # This can happen in the as_p() case (and possibly others
 
176
                    # that users write): if there are only top errors, we may
 
177
                    # not be able to conscript the last row for our purposes,
 
178
                    # so insert a new, empty row.
 
179
                    last_row = normal_row % {'errors': '', 'label': '', 'field': '', 'help_text': ''}
 
180
                    output.append(last_row)
174
181
                output[-1] = last_row[:-len(row_ender)] + str_hidden + row_ender
175
182
            else:
176
183
                # If there aren't any rows in the output, just append the
388
395
 
389
396
        If attrs are given, they're used as HTML attributes on the <label> tag.
390
397
        """
391
 
        contents = contents or escape(self.label)
 
398
        contents = contents or conditional_escape(self.label)
392
399
        widget = self.field.widget
393
400
        id_ = widget.attrs.get('id') or self.auto_id
394
401
        if id_: