Allow list of modules for FORMAT_MODULE_PATH
|Reported by:||mbrochh||Owned by:||mbrochh|
|Severity:||Normal||Keywords:||localization, format files|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
Currently the FORMAT_MODULE_PATH setting (see https://docs.djangoproject.com/en/dev/topics/i18n/formatting/#creating-custom-format-files) only allows a string as a value. This is not optimal because it prevents us from shipping custom format strings with reusable apps.
Imagine the following situation:
- You have created a reusable app that provides a new custom format string for displaying person names
- You have created a reusable app that heavily relies on the format string for SHORT_DATE to be in a specific format and thus provides a formats folder
- In your django project you would like to override some of the other standard format strings
So in this situation you would have one project and two apps each having a formats folder. But we can only set FORMAT_MODULE_PATH to one path.
The code that currently loads those format strings is actually able to deal with a list (see https://github.com/django/django/blob/master/django/utils/formats.py#L67), because first it loads Django's standard formats (see https://github.com/django/django/blob/master/django/utils/formats.py#L46) and then it loads the module defined in FORMAT_MODULE_PATH. It then reverses the list, so that our setting overrides the values of Django's default.
In order to solve this problem, we have copied all this format string loading code and basically just changed line 47, turning the if-clause into a for loop (see https://github.com/bitmazk/django-libs/blob/master/django_libs/format_utils.py#L51).
Now we can set the setting like so:
CUSTOM_FORMAT_MODULE_PATH = [
After working with Django professionally since more than 2 years, I would love to make this my first contribution. If I provided a patch (with tests and documentation), would there be any chance that it will be merged?
Change History (11)
comment:1 Changed 2 years ago by claudep
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
comment:2 Changed 2 years ago by mbrochh
- Owner changed from nobody to mbrochh
- Status changed from new to assigned
comment:9 Changed 15 months ago by Tim Graham <timograham@…>
- Resolution set to fixed
- Status changed from assigned to closed