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
bde81414
Kaydet (Commit)
bde81414
authored
Nis 06, 2017
tarafından
Raphael Michel
Kaydeden (comit)
Florian Apolloner
Nis 07, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22654 -- Broken decimal validation
üst
fd892f34
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
2 deletions
+37
-2
formats.py
django/utils/formats.py
+1
-1
2.0.txt
docs/releases/2.0.txt
+4
-0
test_decimalfield.py
tests/forms_tests/field_tests/test_decimalfield.py
+16
-1
test_floatfield.py
tests/forms_tests/field_tests/test_floatfield.py
+16
-0
No files found.
django/utils/formats.py
Dosyayı görüntüle @
bde81414
...
...
@@ -240,7 +240,7 @@ def sanitize_separators(value):
Sanitize a value according to the current decimal and
thousand separator setting. Used with form field input.
"""
if
settings
.
USE_L10N
and
isinstance
(
value
,
str
):
if
isinstance
(
value
,
str
):
parts
=
[]
decimal_separator
=
get_format
(
'DECIMAL_SEPARATOR'
)
if
decimal_separator
in
value
:
...
...
docs/releases/2.0.txt
Dosyayı görüntüle @
bde81414
...
...
@@ -157,6 +157,10 @@ Forms
HTML attributes for the ``DateInput`` and ``TimeInput`` (or hidden)
subwidgets.
* :class:`~django.forms.FloatField` and :class:`~django.forms.DecimalField`
now handle :setting:`DECIMAL_SEPARATOR` and :setting:`THOUSAND_SEPARATOR`
correctly when :setting:`USE_L10N` is off.
Generic Views
~~~~~~~~~~~~~
...
...
tests/forms_tests/field_tests/test_decimalfield.py
Dosyayı görüntüle @
bde81414
import
decimal
from
django.forms
import
DecimalField
,
NumberInput
,
ValidationError
,
Widget
from
django.test
import
SimpleTestCase
from
django.test
import
SimpleTestCase
,
override_settings
from
django.utils
import
formats
,
translation
from
.
import
FormFieldAssertionsMixin
...
...
@@ -156,3 +156,18 @@ class DecimalFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
f
=
DecimalField
(
max_digits
=
2
,
decimal_places
=
2
,
localize
=
True
)
localized_d
=
formats
.
localize_input
(
d
)
# -> '0,1' in French
self
.
assertFalse
(
f
.
has_changed
(
d
,
localized_d
))
@override_settings
(
USE_L10N
=
False
,
DECIMAL_SEPARATOR
=
','
)
def
test_decimalfield_support_decimal_separator
(
self
):
f
=
DecimalField
(
localize
=
True
)
self
.
assertEqual
(
f
.
clean
(
'1001,10'
),
decimal
.
Decimal
(
"1001.10"
))
self
.
assertEqual
(
f
.
clean
(
'1001.10'
),
decimal
.
Decimal
(
"1001.10"
))
@override_settings
(
USE_L10N
=
False
,
DECIMAL_SEPARATOR
=
','
,
USE_THOUSAND_SEPARATOR
=
True
,
THOUSAND_SEPARATOR
=
'.'
)
def
test_decimalfield_support_thousands_separator
(
self
):
f
=
DecimalField
(
localize
=
True
)
self
.
assertEqual
(
f
.
clean
(
'1.001,10'
),
decimal
.
Decimal
(
"1001.10"
))
msg
=
"'Enter a number.'"
with
self
.
assertRaisesMessage
(
ValidationError
,
msg
):
f
.
clean
(
'1,001.1'
)
tests/forms_tests/field_tests/test_floatfield.py
Dosyayı görüntüle @
bde81414
from
django.forms
import
FloatField
,
NumberInput
,
ValidationError
from
django.test
import
SimpleTestCase
from
django.test.utils
import
override_settings
from
django.utils
import
formats
,
translation
from
.
import
FormFieldAssertionsMixin
...
...
@@ -83,3 +84,18 @@ class FloatFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
f
=
FloatField
(
localize
=
True
)
localized_n
=
formats
.
localize_input
(
n
)
# -> '4,35' in French
self
.
assertFalse
(
f
.
has_changed
(
n
,
localized_n
))
@override_settings
(
USE_L10N
=
False
,
DECIMAL_SEPARATOR
=
','
)
def
test_decimalfield_support_decimal_separator
(
self
):
f
=
FloatField
(
localize
=
True
)
self
.
assertEqual
(
f
.
clean
(
'1001,10'
),
1001.10
)
self
.
assertEqual
(
f
.
clean
(
'1001.10'
),
1001.10
)
@override_settings
(
USE_L10N
=
False
,
DECIMAL_SEPARATOR
=
','
,
USE_THOUSAND_SEPARATOR
=
True
,
THOUSAND_SEPARATOR
=
'.'
)
def
test_decimalfield_support_thousands_separator
(
self
):
f
=
FloatField
(
localize
=
True
)
self
.
assertEqual
(
f
.
clean
(
'1.001,10'
),
1001.10
)
msg
=
"'Enter a number.'"
with
self
.
assertRaisesMessage
(
ValidationError
,
msg
):
f
.
clean
(
'1,001.1'
)
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