Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
d842ada3
Kaydet (Commit)
d842ada3
authored
Nis 27, 2017
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #27795 -- Stopped converting integer format settings to str in JS/JSON i18n views
Thanks Tim Graham for the review.
üst
e3a88c77
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
13 deletions
+30
-13
i18n.py
django/views/i18n.py
+1
-11
2.0.txt
docs/releases/2.0.txt
+3
-0
jsi18n-mocks.test.js
js_tests/admin/jsi18n-mocks.test.js
+2
-2
jsi18n.html
tests/view_tests/templates/jsi18n.html
+8
-0
test_i18n.py
tests/view_tests/tests/test_i18n.py
+16
-0
No files found.
django/views/i18n.py
Dosyayı görüntüle @
d842ada3
...
...
@@ -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"""
...
...
docs/releases/2.0.txt
Dosyayı görüntüle @
d842ada3
...
...
@@ -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
...
...
js_tests/admin/jsi18n-mocks.test.js
Dosyayı görüntüle @
d842ada3
...
...
@@ -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"
:
","
,
...
...
tests/view_tests/templates/jsi18n.html
Dosyayı görüntüle @
d842ada3
...
...
@@ -4,6 +4,14 @@
</head>
<body>
<p
id=
"formats"
>
<script
type=
"text/javascript"
>
document
.
write
(
"DATE_INPUT_FORMATS is an "
+
typeof
get_format
(
"DATE_INPUT_FORMATS"
)
+
"; "
);
document
.
write
(
"DECIMAL_SEPARATOR is a "
+
typeof
get_format
(
"DECIMAL_SEPARATOR"
)
+
"; "
);
document
.
write
(
"FIRST_DAY_OF_WEEK is a "
+
typeof
get_format
(
"FIRST_DAY_OF_WEEK"
)
+
";"
);
</script>
</p>
<p
id=
"gettext"
>
<script
type=
"text/javascript"
>
document
.
write
(
gettext
(
"Remove"
));
...
...
tests/view_tests/tests/test_i18n.py
Dosyayı görüntüle @
d842ada3
...
...
@@ -11,6 +11,7 @@ from django.urls import reverse
from
django.utils.translation
import
(
LANGUAGE_SESSION_KEY
,
get_language
,
override
,
)
from
django.views.i18n
import
get_formats
from
..urls
import
locale_dir
...
...
@@ -183,6 +184,14 @@ class SetLanguageTests(TestCase):
@override_settings
(
ROOT_URLCONF
=
'view_tests.urls'
)
class
I18NViewTests
(
SimpleTestCase
):
"""Test django.views.i18n views other than set_language."""
@override_settings
(
LANGUAGE_CODE
=
'de'
)
def
test_get_formats
(
self
):
formats
=
get_formats
()
# Test 3 possible types in get_formats: integer, string, and list.
self
.
assertEqual
(
formats
[
'FIRST_DAY_OF_WEEK'
],
0
)
self
.
assertEqual
(
formats
[
'DECIMAL_SEPARATOR'
],
'.'
)
self
.
assertEqual
(
formats
[
'TIME_INPUT_FORMATS'
],
[
'
%
H:
%
M:
%
S'
,
'
%
H:
%
M:
%
S.
%
f'
,
'
%
H:
%
M'
])
def
test_jsi18n
(
self
):
"""The javascript_catalog can be deployed with language settings"""
for
lang_code
in
[
'es'
,
'fr'
,
'ru'
]:
...
...
@@ -214,6 +223,8 @@ class I18NViewTests(SimpleTestCase):
data
=
json
.
loads
(
response
.
content
.
decode
())
self
.
assertIn
(
'catalog'
,
data
)
self
.
assertIn
(
'formats'
,
data
)
self
.
assertEqual
(
data
[
'formats'
][
'TIME_INPUT_FORMATS'
],
[
'
%
H:
%
M:
%
S'
,
'
%
H:
%
M:
%
S.
%
f'
,
'
%
H:
%
M'
])
self
.
assertEqual
(
data
[
'formats'
][
'FIRST_DAY_OF_WEEK'
],
0
)
self
.
assertIn
(
'plural'
,
data
)
self
.
assertEqual
(
data
[
'catalog'
][
'month name
\x04
May'
],
'Mai'
)
self
.
assertIn
(
'DATETIME_FORMAT'
,
data
[
'formats'
])
...
...
@@ -398,6 +409,11 @@ class I18nSeleniumTests(SeleniumTestCase):
self
.
assertEqual
(
elem
.
text
,
"1 Resultat"
)
elem
=
self
.
selenium
.
find_element_by_id
(
"npgettext_plur"
)
self
.
assertEqual
(
elem
.
text
,
"455 Resultate"
)
elem
=
self
.
selenium
.
find_element_by_id
(
"formats"
)
self
.
assertEqual
(
elem
.
text
,
"DATE_INPUT_FORMATS is an object; DECIMAL_SEPARATOR is a string; FIRST_DAY_OF_WEEK is a number;"
)
@modify_settings
(
INSTALLED_APPS
=
{
'append'
:
[
'view_tests.app1'
,
'view_tests.app2'
]})
@override_settings
(
LANGUAGE_CODE
=
'fr'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment