Allow configuring Form defaults (like label_suffix) on a per-project basis
|Reported by:||nealtodd||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
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)
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 <firstname.lastname@example.org>\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.
Change History (3)
comment:1 Changed 16 months ago by timo
- Needs documentation unset
- Needs tests unset
- Patch needs improvement set
- Summary changed from Make the default for Form.label_suffix a setting to Allow configuring Form defaults (like label_suffix) on a per-project basis
- Triage Stage changed from Unreviewed to Accepted