From d842ada30524abf410a4de3fc1e539450173800f Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 27 Apr 2017 10:50:48 +0200 Subject: [PATCH] Refs #27795 -- Stopped converting integer format settings to str in JS/JSON i18n views Thanks Tim Graham for the review. --- django/views/i18n.py | 12 +----------- docs/releases/2.0.txt | 3 +++ js_tests/admin/jsi18n-mocks.test.js | 4 ++-- tests/view_tests/templates/jsi18n.html | 8 ++++++++ tests/view_tests/tests/test_i18n.py | 16 ++++++++++++++++ 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/django/views/i18n.py b/django/views/i18n.py index ce78742fd8..261d66fe8c 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -8,7 +8,6 @@ from django.conf import settings from django.http import HttpResponse, HttpResponseRedirect, JsonResponse from django.template import Context, Engine from django.urls import translate_url -from django.utils.encoding import force_text from django.utils.formats import get_format from django.utils.http import is_safe_url from django.utils.translation import ( @@ -68,16 +67,7 @@ def get_formats(): 'THOUSAND_SEPARATOR', 'NUMBER_GROUPING', 'DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS' ) - result = {} - for attr in FORMAT_SETTINGS: - result[attr] = get_format(attr) - formats = {} - for k, v in result.items(): - if isinstance(v, (int, str)): - formats[k] = force_text(v) - elif isinstance(v, (tuple, list)): - formats[k] = [force_text(value) for value in v] - return formats + return {attr: get_format(attr) for attr in FORMAT_SETTINGS} js_catalog_template = r""" diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index 5afe526d13..450d8bd3da 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -326,6 +326,9 @@ Miscellaneous require them. Third-party apps that use these methods may want to adopt a similar approach. +* The ``FIRST_DAY_OF_WEEK`` and ``NUMBER_GROUPING`` format settings are now + kept as integers in JavaScript and JSON i18n view outputs. + .. _deprecated-features-2.0: Features deprecated in 2.0 diff --git a/js_tests/admin/jsi18n-mocks.test.js b/js_tests/admin/jsi18n-mocks.test.js index 4858de6eb3..f04b0576f6 100644 --- a/js_tests/admin/jsi18n-mocks.test.js +++ b/js_tests/admin/jsi18n-mocks.test.js @@ -53,9 +53,9 @@ "%m/%d/%y" ], "DECIMAL_SEPARATOR": ".", - "FIRST_DAY_OF_WEEK": "0", + "FIRST_DAY_OF_WEEK": 0, "MONTH_DAY_FORMAT": "F j", - "NUMBER_GROUPING": "3", + "NUMBER_GROUPING": 3, "SHORT_DATETIME_FORMAT": "m/d/Y P", "SHORT_DATE_FORMAT": "m/d/Y", "THOUSAND_SEPARATOR": ",", diff --git a/tests/view_tests/templates/jsi18n.html b/tests/view_tests/templates/jsi18n.html index d6093c8ef4..df1c4b400c 100644 --- a/tests/view_tests/templates/jsi18n.html +++ b/tests/view_tests/templates/jsi18n.html @@ -4,6 +4,14 @@ +

+ +

+