Ticket #10321: mocksoul_form_label_tag_templates.patch

File mocksoul_form_label_tag_templates.patch, 2.4 KB (added by Vadim Fint, 15 years ago)
  • django/forms/forms.py

    === modified file 'django/forms/forms.py'
     
    7070    # class, not to the Form class.
    7171    def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
    7272                 initial=None, error_class=ErrorList, label_suffix=':',
     73                 label_template='<label for="%(id)s"%(attrs)s>%(contents)s</label>',
    7374                 empty_permitted=False):
    7475        self.is_bound = data is not None or files is not None
    7576        self.data = data or {}
     
    7980        self.initial = initial or {}
    8081        self.error_class = error_class
    8182        self.label_suffix = label_suffix
     83        self.label_template = label_template
    8284        self.empty_permitted = empty_permitted
    8385        self._errors = None # Stores the errors after clean() has been called.
    8486        self._changed_data = None
     
    374376        id_ = widget.attrs.get('id') or self.auto_id
    375377        if id_:
    376378            attrs = attrs and flatatt(attrs) or ''
    377             contents = u'<label for="%s"%s>%s</label>' % (widget.id_for_label(id_), attrs, unicode(contents))
     379            contents = self.form.label_template % {
     380                'id': widget.id_for_label(id_),
     381                'attrs': attrs,
     382                'contents': unicode(contents)
     383            }
    378384        return mark_safe(contents)
    379385
    380386    def _is_hidden(self):
  • django/forms/models.py

    === modified file 'django/forms/models.py'
     
    186186class BaseModelForm(BaseForm):
    187187    def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
    188188                 initial=None, error_class=ErrorList, label_suffix=':',
     189                 label_template='<label for="%(id)s"%(attrs)s>%(contents)s</label>',
    189190                 empty_permitted=False, instance=None):
    190191        opts = self._meta
    191192        if instance is None:
     
    199200        if initial is not None:
    200201            object_data.update(initial)
    201202        super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data,
    202                                             error_class, label_suffix, empty_permitted)
     203                                            error_class, label_suffix, label_template, empty_permitted)
    203204    def clean(self):
    204205        self.validate_unique()
    205206
Back to Top