Opened 4 years ago

Closed 4 years ago

#31052 closed New feature (wontfix)

Let Django users customize FORMAT_SETTINGS (a feature request)

Reported by: אורי Owned by: nobody
Component: Uncategorized Version: 2.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I customized FORMAT_SETTINGS in Speedy Net, you can see more information in this commit:
https://github.com/speedy-net/speedy-net/commit/f5dc4896c136a816ab9fe0dc360d3fd59d0a5f33  

And on Stack Overflow:
https://stackoverflow.com/questions/57188435/django-how-do-i-override-default-date-formats-per-locale 

To customize FORMAT_SETTINGS I had to patch 14 files, because the tests failed and I had to patch the tests too. Is it possible to let Django users customize FORMAT_SETTINGS without having to patch files? For example you can check if the settings contain FORMAT_SETTINGS, and if it is - include these settings in the global FORMAT_SETTINGS (a union, like in the above commit).

formats.FORMAT_SETTINGS = formats.FORMAT_SETTINGS.union(django_settings.FORMAT_SETTINGS)

Change History (3)

comment:1 by אורי, 4 years ago

In django/utils/formats the FORMAT_SETTINGS is defined as a frozenset:
https://github.com/django/django/blob/master/django/utils/formats.py#L31-L46

After this definition, you can add a code such as:

`

if hasattr(settings, 'FORMAT_SETTINGS'):

FORMAT_SETTINGS = FORMAT_SETTINGS.union(settings.FORMAT_SETTINGS)

`

These 2 lines might do the job.

(I tried but I didn't find how to include code here as code).

Last edited 4 years ago by אורי (previous) (diff)

comment:2 by אורי, 4 years ago

Type: UncategorizedNew feature

comment:3 by Carlton Gibson, 4 years ago

Resolution: wontfix
Status: newclosed

I see you created a DevelopersMailingList thread:

https://groups.google.com/d/topic/django-developers/QabCOuVBa1o/discussion

That's good! Let's see if there's an agreement for the change there.
(As per my comment, I'm guessing you should be using Custom format files.)

I'll close this for now, but if there's agreement on the list we can re-open.

Note: See TracTickets for help on using tickets.
Back to Top