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
6d8979f4
Kaydet (Commit)
6d8979f4
authored
Ock 31, 2017
tarafından
Jon Dufresne
Kaydeden (comit)
Tim Graham
Ock 31, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27758 -- Reallowed AdvancedModelIterator pattern after template widget rendering.
üst
3b2e28fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
widgets.py
django/forms/widgets.py
+1
-3
tests.py
tests/model_forms/tests.py
+37
-0
No files found.
django/forms/widgets.py
Dosyayı görüntüle @
6d8979f4
...
...
@@ -552,8 +552,6 @@ class ChoiceWidget(Widget):
for
option_value
,
option_label
in
chain
(
self
.
choices
):
if
option_value
is
None
:
option_value
=
''
else
:
option_value
=
force_text
(
option_value
)
if
isinstance
(
option_label
,
(
list
,
tuple
)):
index
=
groups
[
-
1
][
2
]
+
1
...
...
@@ -569,7 +567,7 @@ class ChoiceWidget(Widget):
for
subvalue
,
sublabel
in
choices
:
selected
=
(
subvalue
in
value
and
force_text
(
subvalue
)
in
value
and
(
has_selected
is
False
or
self
.
allow_multiple_selected
)
)
if
selected
is
True
and
has_selected
is
False
:
...
...
tests/model_forms/tests.py
Dosyayı görüntüle @
6d8979f4
...
...
@@ -15,6 +15,7 @@ from django.forms.models import (
ModelChoiceIterator
,
ModelFormMetaclass
,
construct_instance
,
fields_for_model
,
model_to_dict
,
modelform_factory
,
)
from
django.forms.widgets
import
CheckboxSelectMultiple
from
django.template
import
Context
,
Template
from
django.test
import
SimpleTestCase
,
TestCase
,
skipUnlessDBFeature
...
...
@@ -1704,6 +1705,42 @@ class ModelChoiceFieldTests(TestCase):
field
=
CustomModelChoiceField
(
Category
.
objects
.
all
())
self
.
assertIsInstance
(
field
.
choices
,
CustomModelChoiceIterator
)
def
test_modelchoicefield_iterator_pass_model_to_widget
(
self
):
class
CustomModelChoiceValue
:
def
__init__
(
self
,
value
,
obj
):
self
.
value
=
value
self
.
obj
=
obj
def
__str__
(
self
):
return
str
(
self
.
value
)
class
CustomModelChoiceIterator
(
ModelChoiceIterator
):
def
choice
(
self
,
obj
):
value
,
label
=
super
()
.
choice
(
obj
)
return
CustomModelChoiceValue
(
value
,
obj
),
label
class
CustomCheckboxSelectMultiple
(
CheckboxSelectMultiple
):
def
create_option
(
self
,
name
,
value
,
label
,
selected
,
index
,
subindex
=
None
,
attrs
=
None
):
option
=
super
()
.
create_option
(
name
,
value
,
label
,
selected
,
index
,
subindex
=
None
,
attrs
=
None
)
# Modify the HTML based on the object being rendered.
c
=
value
.
obj
option
[
'attrs'
][
'data-slug'
]
=
c
.
slug
return
option
class
CustomModelMultipleChoiceField
(
forms
.
ModelMultipleChoiceField
):
iterator
=
CustomModelChoiceIterator
widget
=
CustomCheckboxSelectMultiple
field
=
CustomModelMultipleChoiceField
(
Category
.
objects
.
all
())
self
.
assertHTMLEqual
(
field
.
widget
.
render
(
'name'
,
[]),
'''<ul>
<li><label><input type="checkbox" name="name" value="
%
d" data-slug="entertainment" />Entertainment</label></li>
<li><label><input type="checkbox" name="name" value="
%
d" data-slug="its-test" />It's a test</label></li>
<li><label><input type="checkbox" name="name" value="
%
d" data-slug="third-test" />Third</label></li>
</ul>'''
%
(
self
.
c1
.
pk
,
self
.
c2
.
pk
,
self
.
c3
.
pk
),
)
def
test_modelchoicefield_num_queries
(
self
):
"""
Widgets that render multiple subwidgets shouldn't make more than one
...
...
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