#22937: Make the default for Form.label_suffix a setting
-----------------------------+--------------------
     Reporter:  nealtodd     |      Owner:  nobody
         Type:  New feature  |     Status:  new
    Component:  Forms        |    Version:  master
     Severity:  Normal       |   Keywords:
 Triage Stage:  Unreviewed   |  Has patch:  1
Easy pickings:  0            |      UI/UX:  0
-----------------------------+--------------------
 Currently, the default for
 
[https://docs.djangoproject.com/en/dev/ref/forms/api/#django.forms.Form.label_suffix
 Form.label_suffix] (a colon (:) in English) is hardcoded in
 [https://github.com/django/django/blob/master/django/forms/forms.py#L122
 forms.py].

 Although this default can be overridden in individual Form and Field
 instantiation, the hardcoding makes it difficult to globally set a
 different default label suffix across a whole project. A workaround such
 as having a base form that sets the attribute does work, but requires all
 the forms in a project to inherit from it rather than just from, e.g.,
 forms.Form:

 {{{
 class BaseForm(forms.Form):
     def __init__(self, *args, **kwargs):
         kwargs.setdefault('label_suffix', '')
         super(BaseForm, self).__init__(*args, **kwargs)
 }}}

 [https://github.com/nealtodd/django/tree/label_suffix_setting This branch]
 pulls the default for Form.label_suffix out of forms.py and into a
 `django.conf.settings`.

 It includes tests and documentation. All Django tests pass using
 `test_sqlite`.

 It is backwards compatible as it is included in global settings with a
 default of ':'.

 A typical use-case, and the reason for submitting this patch, is to use an
 empty string for the label suffix. Note in the implementation that there's
 special handling for that case because translating an empty string doesn't
 result in an empty string (because of the placement of the .po file
 version strings):

 {{{
 >>> from django.utils.translation import ugettext as _
 >>> _('')
 u'Project-Id-Version: Django\nReport-Msgid-Bugs-To: \nPOT-Creation-Date:
 2013-10-09 20:17+0200\nPO-Revision-Date: 2010-05-13 15:35+0200\nLast-
 Translator: Django team\nLanguage-Team: English <[email protected]>\nLanguage: en
 \nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-
 Transfer-Encoding: 8bit\n'
 }}}

 Hope it'll be considered useful enough for a PR.

 Regards, Neal

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22937>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.5a1048c9c17bcd61b5c2d1b807570b2f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to