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
0adfba96
Kaydet (Commit)
0adfba96
authored
Tem 19, 2018
tarafından
Claude Paroz
Kaydeden (comit)
Tim Graham
Tem 19, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29578 -- Made numberformat.format() honor forced l10n usage.
Thanks Sassan Haradji for the report.
üst
6b6bdfe2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
18 deletions
+26
-18
formats.py
django/utils/formats.py
+2
-1
numberformat.py
django/utils/numberformat.py
+2
-2
test_actions.py
tests/admin_views/test_actions.py
+1
-1
tests.py
tests/i18n/tests.py
+14
-12
test_numberformat.py
tests/utils_tests/test_numberformat.py
+7
-2
No files found.
django/utils/formats.py
Dosyayı görüntüle @
0adfba96
...
@@ -179,7 +179,8 @@ def number_format(value, decimal_pos=None, use_l10n=None, force_grouping=False):
...
@@ -179,7 +179,8 @@ def number_format(value, decimal_pos=None, use_l10n=None, force_grouping=False):
decimal_pos
,
decimal_pos
,
get_format
(
'NUMBER_GROUPING'
,
lang
,
use_l10n
=
use_l10n
),
get_format
(
'NUMBER_GROUPING'
,
lang
,
use_l10n
=
use_l10n
),
get_format
(
'THOUSAND_SEPARATOR'
,
lang
,
use_l10n
=
use_l10n
),
get_format
(
'THOUSAND_SEPARATOR'
,
lang
,
use_l10n
=
use_l10n
),
force_grouping
=
force_grouping
force_grouping
=
force_grouping
,
use_l10n
=
use_l10n
,
)
)
...
...
django/utils/numberformat.py
Dosyayı görüntüle @
0adfba96
...
@@ -5,7 +5,7 @@ from django.utils.safestring import mark_safe
...
@@ -5,7 +5,7 @@ from django.utils.safestring import mark_safe
def
format
(
number
,
decimal_sep
,
decimal_pos
=
None
,
grouping
=
0
,
thousand_sep
=
''
,
def
format
(
number
,
decimal_sep
,
decimal_pos
=
None
,
grouping
=
0
,
thousand_sep
=
''
,
force_grouping
=
False
):
force_grouping
=
False
,
use_l10n
=
None
):
"""
"""
Get a number (as a number or string), and return it as a string,
Get a number (as a number or string), and return it as a string,
using formats defined as arguments:
using formats defined as arguments:
...
@@ -18,7 +18,7 @@ def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='',
...
@@ -18,7 +18,7 @@ def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='',
module in locale.localeconv() LC_NUMERIC grouping (e.g. (3, 2, 0)).
module in locale.localeconv() LC_NUMERIC grouping (e.g. (3, 2, 0)).
* thousand_sep: Thousand separator symbol (for example ",")
* thousand_sep: Thousand separator symbol (for example ",")
"""
"""
use_grouping
=
settings
.
USE_L10N
and
settings
.
USE_THOUSAND_SEPARATOR
use_grouping
=
(
use_l10n
or
(
use_l10n
is
None
and
settings
.
USE_L10N
))
and
settings
.
USE_THOUSAND_SEPARATOR
use_grouping
=
use_grouping
or
force_grouping
use_grouping
=
use_grouping
or
force_grouping
use_grouping
=
use_grouping
and
grouping
!=
0
use_grouping
=
use_grouping
and
grouping
!=
0
# Make the common case fast
# Make the common case fast
...
...
tests/admin_views/test_actions.py
Dosyayı görüntüle @
0adfba96
...
@@ -72,7 +72,7 @@ class AdminActionsTest(TestCase):
...
@@ -72,7 +72,7 @@ class AdminActionsTest(TestCase):
self
.
assertContains
(
response
,
'Are you sure you want to delete the selected subscribers?'
)
self
.
assertContains
(
response
,
'Are you sure you want to delete the selected subscribers?'
)
self
.
assertContains
(
response
,
'<ul></ul>'
,
html
=
True
)
self
.
assertContains
(
response
,
'<ul></ul>'
,
html
=
True
)
@override_settings
(
USE_THOUSAND_SEPARATOR
=
True
,
USE_L10N
=
True
)
@override_settings
(
USE_THOUSAND_SEPARATOR
=
True
,
USE_L10N
=
True
,
NUMBER_GROUPING
=
3
)
def
test_non_localized_pk
(
self
):
def
test_non_localized_pk
(
self
):
"""
"""
If USE_THOUSAND_SEPARATOR is set, the ids for the objects selected for
If USE_THOUSAND_SEPARATOR is set, the ids for the objects selected for
...
...
tests/i18n/tests.py
Dosyayı görüntüle @
0adfba96
...
@@ -1039,33 +1039,35 @@ class FormattingTests(SimpleTestCase):
...
@@ -1039,33 +1039,35 @@ class FormattingTests(SimpleTestCase):
"""
"""
Test the {
%
localize
%
} templatetag and the localize/unlocalize filters.
Test the {
%
localize
%
} templatetag and the localize/unlocalize filters.
"""
"""
context
=
Context
({
'float'
:
3.14
,
'date'
:
datetime
.
date
(
2016
,
12
,
31
)})
context
=
Context
({
'
int'
:
1455
,
'
float'
:
3.14
,
'date'
:
datetime
.
date
(
2016
,
12
,
31
)})
template1
=
Template
(
template1
=
Template
(
'{
%
load l10n
%
}{
%
localize
%
}{{ float }}/{{ date }}{
%
endlocalize
%
}; '
'{
%
load l10n
%
}{
%
localize
%
}{{
int }}/{{
float }}/{{ date }}{
%
endlocalize
%
}; '
'{
%
localize on
%
}{{ float }}/{{ date }}{
%
endlocalize
%
}'
'{
%
localize on
%
}{{
int }}/{{
float }}/{{ date }}{
%
endlocalize
%
}'
)
)
template2
=
Template
(
template2
=
Template
(
'{
%
load l10n
%
}{{ float }}/{{ date }}; '
'{
%
load l10n
%
}{{
int }}/{{
float }}/{{ date }}; '
'{
%
localize off
%
}{{ float }}/{{ date }};{
%
endlocalize
%
} '
'{
%
localize off
%
}{{
int }}/{{
float }}/{{ date }};{
%
endlocalize
%
} '
'{{ float }}/{{ date }}'
'{{
int }}/{{
float }}/{{ date }}'
)
)
template3
=
Template
(
template3
=
Template
(
'{
%
load l10n
%
}{{ float }}/{{ date }}; {{ float|unlocalize }}/{{ date|unlocalize }}'
'{
%
load l10n
%
}{{ int }}/{{ float }}/{{ date }}; '
'{{ int|unlocalize }}/{{ float|unlocalize }}/{{ date|unlocalize }}'
)
)
template4
=
Template
(
template4
=
Template
(
'{
%
load l10n
%
}{{ float }}/{{ date }}; {{ float|localize }}/{{ date|localize }}'
'{
%
load l10n
%
}{{ int }}/{{ float }}/{{ date }}; '
'{{ int|localize }}/{{ float|localize }}/{{ date|localize }}'
)
)
expected_localized
=
'3,14/31. Dezember 2016'
expected_localized
=
'
1.455/
3,14/31. Dezember 2016'
expected_unlocalized
=
'3.14/Dez. 31, 2016'
expected_unlocalized
=
'
1455/
3.14/Dez. 31, 2016'
output1
=
'; '
.
join
([
expected_localized
,
expected_localized
])
output1
=
'; '
.
join
([
expected_localized
,
expected_localized
])
output2
=
'; '
.
join
([
expected_localized
,
expected_unlocalized
,
expected_localized
])
output2
=
'; '
.
join
([
expected_localized
,
expected_unlocalized
,
expected_localized
])
output3
=
'; '
.
join
([
expected_localized
,
expected_unlocalized
])
output3
=
'; '
.
join
([
expected_localized
,
expected_unlocalized
])
output4
=
'; '
.
join
([
expected_unlocalized
,
expected_localized
])
output4
=
'; '
.
join
([
expected_unlocalized
,
expected_localized
])
with
translation
.
override
(
'de'
,
deactivate
=
True
):
with
translation
.
override
(
'de'
,
deactivate
=
True
):
with
self
.
settings
(
USE_L10N
=
False
):
with
self
.
settings
(
USE_L10N
=
False
,
USE_THOUSAND_SEPARATOR
=
True
):
self
.
assertEqual
(
template1
.
render
(
context
),
output1
)
self
.
assertEqual
(
template1
.
render
(
context
),
output1
)
self
.
assertEqual
(
template4
.
render
(
context
),
output4
)
self
.
assertEqual
(
template4
.
render
(
context
),
output4
)
with
self
.
settings
(
USE_L10N
=
True
):
with
self
.
settings
(
USE_L10N
=
True
,
USE_THOUSAND_SEPARATOR
=
True
):
self
.
assertEqual
(
template1
.
render
(
context
),
output1
)
self
.
assertEqual
(
template1
.
render
(
context
),
output1
)
self
.
assertEqual
(
template2
.
render
(
context
),
output2
)
self
.
assertEqual
(
template2
.
render
(
context
),
output2
)
self
.
assertEqual
(
template3
.
render
(
context
),
output3
)
self
.
assertEqual
(
template3
.
render
(
context
),
output3
)
...
...
tests/utils_tests/test_numberformat.py
Dosyayı görüntüle @
0adfba96
from
decimal
import
Decimal
from
decimal
import
Decimal
from
sys
import
float_info
from
sys
import
float_info
from
unittest
import
TestCase
from
django.test
import
SimpleTestCase
from
django.utils.numberformat
import
format
as
nformat
from
django.utils.numberformat
import
format
as
nformat
class
TestNumberFormat
(
TestCase
):
class
TestNumberFormat
(
Simple
TestCase
):
def
test_format_number
(
self
):
def
test_format_number
(
self
):
self
.
assertEqual
(
nformat
(
1234
,
'.'
),
'1234'
)
self
.
assertEqual
(
nformat
(
1234
,
'.'
),
'1234'
)
...
@@ -14,6 +14,11 @@ class TestNumberFormat(TestCase):
...
@@ -14,6 +14,11 @@ class TestNumberFormat(TestCase):
self
.
assertEqual
(
nformat
(
1234
,
'.'
,
grouping
=
2
,
thousand_sep
=
','
),
'1234'
)
self
.
assertEqual
(
nformat
(
1234
,
'.'
,
grouping
=
2
,
thousand_sep
=
','
),
'1234'
)
self
.
assertEqual
(
nformat
(
1234
,
'.'
,
grouping
=
2
,
thousand_sep
=
','
,
force_grouping
=
True
),
'12,34'
)
self
.
assertEqual
(
nformat
(
1234
,
'.'
,
grouping
=
2
,
thousand_sep
=
','
,
force_grouping
=
True
),
'12,34'
)
self
.
assertEqual
(
nformat
(
-
1234.33
,
'.'
,
decimal_pos
=
1
),
'-1234.3'
)
self
.
assertEqual
(
nformat
(
-
1234.33
,
'.'
,
decimal_pos
=
1
),
'-1234.3'
)
# The use_l10n parameter can force thousand grouping behavior.
with
self
.
settings
(
USE_THOUSAND_SEPARATOR
=
True
,
USE_L10N
=
True
):
self
.
assertEqual
(
nformat
(
1234
,
'.'
,
grouping
=
3
,
thousand_sep
=
','
,
use_l10n
=
False
),
'1234'
)
with
self
.
settings
(
USE_THOUSAND_SEPARATOR
=
True
,
USE_L10N
=
False
):
self
.
assertEqual
(
nformat
(
1234
,
'.'
,
grouping
=
3
,
thousand_sep
=
','
,
use_l10n
=
True
),
'1,234'
)
def
test_format_string
(
self
):
def
test_format_string
(
self
):
self
.
assertEqual
(
nformat
(
'1234'
,
'.'
),
'1234'
)
self
.
assertEqual
(
nformat
(
'1234'
,
'.'
),
'1234'
)
...
...
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