#35153: FORMAT_MODULE_PATH not acting as I expected.
-------------------------------------+-------------------------------------
Reporter: Paul | Owner: nobody
Hermans |
Type: Bug | Status: new
Component: | Version: 5.0
Documentation |
Severity: Normal | Keywords: FORMAT_MODULE_PATH
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
I am not certain this is a bug, but may be more of a confusion of a new
user (me). Here is what I found:
In my **settings**:
{{{
LANGUAGE_CODE='en-us'
TIME_ZONE = 'America/New_York'
FORMAT_MODULE_PATH = [
"student_track.formats",
]
USE_L10N=True
USE_I18N = True
USE_TZ = True
USE_THOUSAND_SEPARATOR = True
}}}
then in my student_track app:
I had this file:
{{{
/formats/en_us/formats.py
}}}
but this failed to load (no error message). Eventually I figured out to
change the file path to this (Note the Upper Case for the country):
{{{
/formats/en_US/formats.py
}}}
In my **formats.py** i still have:
{{{
DATE_FORMAT = "M. d, Y"
TIME_FORMAT = "h:i a"
DATETIME_FORMAT = "M. d Y h:i a"
# DATETIME_FORMAT = f"{DATE_FORMAT} {TIME_FORMAT}"
DATE_INPUT_FORMATS = [
'%m/%d/%Y', '%m/%d/%y', '%Y-%m-%d', # '2006-10-25', '10/25/2006',
'10/25/06'
'%b %d %Y', '%b %d, %Y', # 'Oct 25 2006', 'Oct 25, 2006'
'%d %b %Y', '%d %b, %Y', # '25 Oct 2006', '25 Oct, 2006'
'%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006'
'%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006'
]
}}}
**Template** I now have:
{{{
<td class="text-start" >{{ record.actual_date }} </td>
}}}
and all is working well.
Where I think the issue is that the folder name did not match the language
I specified in the settings file and I didn't understand that from the
documentation.
When I stepped through the code, it seems that this change occurs in the
**django.utils.formats.py** file when iter_format_modules() is called:
{{{
def iter_format_modules(lang, format_module_path=None):
"""Find format modules."""
if not check_for_language(lang):
return
if format_module_path is None:
format_module_path = settings.FORMAT_MODULE_PATH
format_locations = []
if format_module_path:
if isinstance(format_module_path, str):
format_module_path = [format_module_path]
for path in format_module_path:
format_locations.append(path + ".%s")
format_locations.append("django.conf.locale.%s")
locale = to_locale(lang)
locales = [locale]
if "_" in locale:
locales.append(locale.split("_")[0])
for location in format_locations:
for loc in locales:
try:
yield import_module("%s.formats" % (location % loc))
except ImportError:
pass
}}}
In my case, this failed with an ImportError, and when I looked into its
details, it seems that this line:
{{{
locale = to_locale(lang)
}}}
converted had my language specified in settings (en-us) to "en_US".
I don't exactly know why, but it seems intentional. Assuming this is
behaving as expected, then it seems that the documentation should be
updated to indicate how this works.
I am so new to Django that I am hesitant to propose the actual text that
should change, but would be happy to try/help if this seems like the
reasonable solution.
--
Ticket URL: <https://code.djangoproject.com/ticket/35153>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018d582d0f3b-7a1ded2c-4dcd-44e6-a60b-b1e14051662f-000000%40eu-central-1.amazonses.com.