[Django] #20477: Allow list of modules for FORMAT_MODULE_PATH

49 views
Skip to first unread message

Django

unread,
May 22, 2013, 6:24:07 AM5/22/13
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: nobody
Type: New feature | Status: new
Component: | Version: master
Internationalization | Keywords: localization, format
Severity: Normal | files
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
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 = [
'my_django_project.formats',
'my_person_name_app.formats',
'my_short_date_app.formats',
]

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?

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

Django

unread,
May 22, 2013, 7:59:04 AM5/22/13
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: nobody
Type: New feature | Status: new
Component: | Version: master
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: localization, | Needs documentation: 0
format files | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by claudep):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

Yes, it makes sense for me.

--
Ticket URL: <https://code.djangoproject.com/ticket/20477#comment:1>

Django

unread,
May 22, 2013, 12:39:42 PM5/22/13
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: mbrochh
Type: New feature | Status: assigned

Component: | Version: master
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: localization, | Needs documentation: 0
format files | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by mbrochh):

* status: new => assigned
* owner: nobody => mbrochh


--
Ticket URL: <https://code.djangoproject.com/ticket/20477#comment:2>

Django

unread,
Jun 1, 2013, 2:38:03 PM6/1/13
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: mbrochh
Type: New feature | Status: assigned
Component: | Version: master
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: localization, | Needs documentation: 0
format files | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by Martin Brochhaus <mbrochh@…>):

Created pull request: https://github.com/django/django/pull/1236

I actually only replaced one line of Django code with a few more lines.
The change is quite trivial.
The original code was not yet covered by the test suite, so I added new
tests and increased the test coverage for `utils/formats.py`.
I also updated to docs.

Hope this is all good :)

--
Ticket URL: <https://code.djangoproject.com/ticket/20477#comment:3>

Django

unread,
Jun 1, 2013, 2:38:45 PM6/1/13
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: mbrochh
Type: New feature | Status: assigned
Component: | Version: master
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: localization, | Needs documentation: 0
format files | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0

Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by Martin Brochhaus <mbrochh@…>):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/20477#comment:4>

Django

unread,
Jun 2, 2013, 2:17:50 AM6/2/13
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: mbrochh
Type: New feature | Status: assigned
Component: | Version: master
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: localization, | Needs documentation: 0
format files | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by Martin Brochhaus <mbrochh@…>):

Update: I added some comments to the pull request to make codereview
easier.

--
Ticket URL: <https://code.djangoproject.com/ticket/20477#comment:5>

Django

unread,
Sep 18, 2013, 4:16:52 PM9/18/13
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: mbrochh
Type: New feature | Status: assigned
Component: | Version: master
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: localization, | Needs documentation: 0
format files | Patch needs improvement: 1

Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by timo):

* needs_better_patch: 0 => 1


Comment:

There are comments on the pull request indicating it needs improvement.

--
Ticket URL: <https://code.djangoproject.com/ticket/20477#comment:6>

Django

unread,
Oct 9, 2013, 1:42:56 PM10/9/13
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: mbrochh
Type: New feature | Status: assigned
Component: | Version: master
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: localization, | Needs documentation: 0
format files | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* easy: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/20477#comment:7>

Django

unread,
Oct 24, 2013, 11:03:30 AM10/24/13
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: mbrochh
Type: New feature | Status: assigned
Component: | Version: master
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: localization, | Needs documentation: 0
format files | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by mbrochh):

@timo I have done the requested improvement:
https://github.com/django/django/pull/1236

--
Ticket URL: <https://code.djangoproject.com/ticket/20477#comment:8>

Django

unread,
May 19, 2014, 8:01:34 AM5/19/14
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: mbrochh
Type: New feature | Status: closed
Component: | Version: master
Internationalization | Resolution: fixed

Severity: Normal | Triage Stage: Accepted
Keywords: localization, | Needs documentation: 0
format files | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"950b6de16ac2f8135612f2ed5984c090dd8e4dcf"]:
{{{
#!CommitTicketReference repository=""
revision="950b6de16ac2f8135612f2ed5984c090dd8e4dcf"
Fixed #20477: Allowed settings.FORMAT_MODULE_PATH to be a list of modules.

Previously the FORMAT_MODULE_PATH setting only accepted one string (dotted
module path).

This is useful when using several reusable third party apps that define
new
formats. We can now use them all and we can even override some of the
formats
by providing a project-wide format module.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20477#comment:9>

Django

unread,
May 19, 2014, 8:23:11 AM5/19/14
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: mbrochh
Type: New feature | Status: closed
Component: | Version: master
Internationalization | Resolution: fixed
Severity: Normal | Triage Stage: Accepted
Keywords: localization, | Needs documentation: 0
format files | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"5abc811a40dbeee092b9f50055d229e9c24274fa"]:
{{{
#!CommitTicketReference repository=""
revision="5abc811a40dbeee092b9f50055d229e9c24274fa"
Revert "Fixed #20477: Allowed settings.FORMAT_MODULE_PATH to be a list of
modules."

This reverts commit 950b6de16ac2f8135612f2ed5984c090dd8e4dcf.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20477#comment:10>

Django

unread,
May 21, 2014, 7:55:15 AM5/21/14
to django-...@googlegroups.com
#20477: Allow list of modules for FORMAT_MODULE_PATH
-------------------------------------+-------------------------------------
Reporter: mbrochh | Owner: mbrochh
Type: New feature | Status: closed
Component: | Version: master
Internationalization | Resolution: fixed
Severity: Normal | Triage Stage: Accepted
Keywords: localization, | Needs documentation: 0
format files | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"bb0a9a070b9570c85bcb17346dae6513e4ba6e76"]:
{{{
#!CommitTicketReference repository=""
revision="bb0a9a070b9570c85bcb17346dae6513e4ba6e76"
Fixed #20477: Allowed list of modules for FORMAT_MODULE_PATH

Previously the FORMAT_MODULE_PATH setting only accepted one string (dotted

module path). A feature has been added to also allow a list of strings.

This is useful when using several reusable third party apps that define
new
formats. We can now use them all and we can even override some of the
formats
by providing a project-wide format module.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20477#comment:11>

Reply all
Reply to author
Forward
0 new messages