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
218175b0
Kaydet (Commit)
218175b0
authored
Nis 24, 2016
tarafından
David Sanders
Kaydeden (comit)
Simon Charette
Nis 24, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26534 -- Fixed boolean form fields has_changed() with hidden input.
üst
18888304
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
14 deletions
+15
-14
fields.py
django/forms/fields.py
+3
-14
test_booleanfield.py
tests/forms_tests/field_tests/test_booleanfield.py
+5
-0
test_nullbooleanfield.py
tests/forms_tests/field_tests/test_nullbooleanfield.py
+7
-0
No files found.
django/forms/fields.py
Dosyayı görüntüle @
218175b0
...
...
@@ -720,12 +720,9 @@ class BooleanField(Field):
raise
ValidationError
(
self
.
error_messages
[
'required'
],
code
=
'required'
)
def
has_changed
(
self
,
initial
,
data
):
# Sometimes data or initial could be None or '' which should be the
# same thing as False.
if
initial
==
'False'
:
# show_hidden_initial may have transformed False to 'False'
initial
=
False
return
bool
(
initial
)
!=
bool
(
data
)
# Sometimes data or initial may be a string equivalent of a boolean
# so we should run it through to_python first to get a boolean value
return
self
.
to_python
(
initial
)
!=
self
.
to_python
(
data
)
class
NullBooleanField
(
BooleanField
):
...
...
@@ -754,14 +751,6 @@ class NullBooleanField(BooleanField):
def
validate
(
self
,
value
):
pass
def
has_changed
(
self
,
initial
,
data
):
# None (unknown) and False (No) are not the same
if
initial
is
not
None
:
initial
=
bool
(
initial
)
if
data
is
not
None
:
data
=
bool
(
data
)
return
initial
!=
data
class
CallableChoiceIterator
(
object
):
def
__init__
(
self
,
choices_func
):
...
...
tests/forms_tests/field_tests/test_booleanfield.py
Dosyayı görüntüle @
218175b0
...
...
@@ -54,3 +54,8 @@ class BooleanFieldTest(SimpleTestCase):
self
.
assertTrue
(
f
.
has_changed
(
True
,
''
))
# Initial value may have mutated to a string due to show_hidden_initial (#19537)
self
.
assertTrue
(
f
.
has_changed
(
'False'
,
'on'
))
# HiddenInput widget sends string values for boolean but doesn't clean them in value_from_datadict
self
.
assertFalse
(
f
.
has_changed
(
False
,
'False'
))
self
.
assertFalse
(
f
.
has_changed
(
True
,
'True'
))
self
.
assertTrue
(
f
.
has_changed
(
False
,
'True'
))
self
.
assertTrue
(
f
.
has_changed
(
True
,
'False'
))
tests/forms_tests/field_tests/test_nullbooleanfield.py
Dosyayı görüntüle @
218175b0
...
...
@@ -67,3 +67,10 @@ class NullBooleanFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
self
.
assertTrue
(
f
.
has_changed
(
True
,
False
))
self
.
assertTrue
(
f
.
has_changed
(
True
,
None
))
self
.
assertTrue
(
f
.
has_changed
(
True
,
False
))
# HiddenInput widget sends string values for boolean but doesn't clean them in value_from_datadict
self
.
assertFalse
(
f
.
has_changed
(
False
,
'False'
))
self
.
assertFalse
(
f
.
has_changed
(
True
,
'True'
))
self
.
assertFalse
(
f
.
has_changed
(
None
,
''
))
self
.
assertTrue
(
f
.
has_changed
(
False
,
'True'
))
self
.
assertTrue
(
f
.
has_changed
(
True
,
'False'
))
self
.
assertTrue
(
f
.
has_changed
(
None
,
'False'
))
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