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
d302e2c0
Kaydet (Commit)
d302e2c0
authored
May 03, 2017
tarafından
Tim Graham
Kaydeden (comit)
GitHub
May 03, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28157 -- Fixed choice ordering in form fields with grouped and non-grouped options.
Regression in
b52c7300
.
üst
13cd5b06
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
37 deletions
+76
-37
widgets.py
django/forms/widgets.py
+6
-8
1.11.1.txt
docs/releases/1.11.1.txt
+3
-0
test_select.py
tests/forms_tests/widget_tests/test_select.py
+67
-29
No files found.
django/forms/widgets.py
Dosyayı görüntüle @
d302e2c0
...
@@ -547,25 +547,23 @@ class ChoiceWidget(Widget):
...
@@ -547,25 +547,23 @@ class ChoiceWidget(Widget):
def
optgroups
(
self
,
name
,
value
,
attrs
=
None
):
def
optgroups
(
self
,
name
,
value
,
attrs
=
None
):
"""Return a list of optgroups for this widget."""
"""Return a list of optgroups for this widget."""
default
=
(
None
,
[],
0
)
groups
=
[]
groups
=
[
default
]
has_selected
=
False
has_selected
=
False
for
option_value
,
option_label
in
chain
(
self
.
choices
):
for
index
,
(
option_value
,
option_label
)
in
enumerate
(
chain
(
self
.
choices
)
):
if
option_value
is
None
:
if
option_value
is
None
:
option_value
=
''
option_value
=
''
subgroup
=
[]
if
isinstance
(
option_label
,
(
list
,
tuple
)):
if
isinstance
(
option_label
,
(
list
,
tuple
)):
index
=
groups
[
-
1
][
2
]
+
1
group_name
=
option_value
subindex
=
0
subindex
=
0
subgroup
=
[]
groups
.
append
((
option_value
,
subgroup
,
index
))
choices
=
option_label
choices
=
option_label
else
:
else
:
index
=
len
(
default
[
1
])
group_name
=
None
subgroup
=
default
[
1
]
subindex
=
None
subindex
=
None
choices
=
[(
option_value
,
option_label
)]
choices
=
[(
option_value
,
option_label
)]
groups
.
append
((
group_name
,
subgroup
,
index
))
for
subvalue
,
sublabel
in
choices
:
for
subvalue
,
sublabel
in
choices
:
selected
=
(
selected
=
(
...
...
docs/releases/1.11.1.txt
Dosyayı görüntüle @
d302e2c0
...
@@ -78,3 +78,6 @@ Bugfixes
...
@@ -78,3 +78,6 @@ Bugfixes
* Prevented migrations from dropping database indexes from ``Meta.indexes``
* Prevented migrations from dropping database indexes from ``Meta.indexes``
when changing ``Field.db_index`` to ``False`` (:ticket:`28052`).
when changing ``Field.db_index`` to ``False`` (:ticket:`28052`).
* Fixed a regression in choice ordering in form fields with grouped and
non-grouped options (:ticket:`28157`).
tests/forms_tests/widget_tests/test_select.py
Dosyayı görüntüle @
d302e2c0
...
@@ -280,35 +280,73 @@ class SelectTest(WidgetTest):
...
@@ -280,35 +280,73 @@ class SelectTest(WidgetTest):
groups
=
list
(
self
.
widget
(
choices
=
choices
)
.
optgroups
(
groups
=
list
(
self
.
widget
(
choices
=
choices
)
.
optgroups
(
'name'
,
[
'vhs'
],
attrs
=
{
'class'
:
'super'
},
'name'
,
[
'vhs'
],
attrs
=
{
'class'
:
'super'
},
))
))
self
.
assertEqual
(
len
(
groups
),
3
)
audio
,
video
,
unknown
=
groups
self
.
assertEqual
(
groups
[
0
][
0
],
None
)
label
,
options
,
index
=
audio
self
.
assertEqual
(
groups
[
0
][
2
],
0
)
self
.
assertEqual
(
label
,
'Audio'
)
self
.
assertEqual
(
len
(
groups
[
0
][
1
]),
1
)
self
.
assertEqual
(
options
=
groups
[
0
][
1
]
options
,
self
.
assertEqual
(
options
[
0
][
'name'
],
'name'
)
[{
self
.
assertEqual
(
options
[
0
][
'value'
],
'unknown'
)
'value'
:
'vinyl'
,
self
.
assertEqual
(
options
[
0
][
'label'
],
'Unknown'
)
'type'
:
'select'
,
self
.
assertEqual
(
options
[
0
][
'index'
],
'0'
)
'attrs'
:
{},
self
.
assertEqual
(
options
[
0
][
'selected'
],
False
)
'index'
:
'0_0'
,
self
.
assertEqual
(
groups
[
1
][
0
],
'Audio'
)
'label'
:
'Vinyl'
,
self
.
assertEqual
(
groups
[
1
][
2
],
1
)
'template_name'
:
'django/forms/widgets/select_option.html'
,
self
.
assertEqual
(
len
(
groups
[
1
][
1
]),
2
)
'name'
:
'name'
,
options
=
groups
[
1
][
1
]
'selected'
:
False
,
self
.
assertEqual
(
options
[
0
][
'name'
],
'name'
)
},
{
self
.
assertEqual
(
options
[
0
][
'value'
],
'vinyl'
)
'value'
:
'cd'
,
self
.
assertEqual
(
options
[
0
][
'label'
],
'Vinyl'
)
'type'
:
'select'
,
self
.
assertEqual
(
options
[
0
][
'index'
],
'1_0'
)
'attrs'
:
{},
self
.
assertEqual
(
options
[
1
][
'index'
],
'1_1'
)
'index'
:
'0_1'
,
self
.
assertEqual
(
groups
[
2
][
0
],
'Video'
)
'label'
:
'CD'
,
self
.
assertEqual
(
groups
[
2
][
2
],
2
)
'template_name'
:
'django/forms/widgets/select_option.html'
,
self
.
assertEqual
(
len
(
groups
[
2
][
1
]),
2
)
'name'
:
'name'
,
options
=
groups
[
2
][
1
]
'selected'
:
False
,
self
.
assertEqual
(
options
[
0
][
'name'
],
'name'
)
}]
self
.
assertEqual
(
options
[
0
][
'value'
],
'vhs'
)
)
self
.
assertEqual
(
options
[
0
][
'label'
],
'VHS Tape'
)
self
.
assertEqual
(
index
,
0
)
self
.
assertEqual
(
options
[
0
][
'index'
],
'2_0'
)
label
,
options
,
index
=
video
self
.
assertEqual
(
options
[
0
][
'selected'
],
True
)
self
.
assertEqual
(
label
,
'Video'
)
self
.
assertEqual
(
options
[
1
][
'index'
],
'2_1'
)
self
.
assertEqual
(
options
,
[{
'value'
:
'vhs'
,
'template_name'
:
'django/forms/widgets/select_option.html'
,
'label'
:
'VHS Tape'
,
'attrs'
:
{
'selected'
:
True
},
'index'
:
'1_0'
,
'name'
:
'name'
,
'selected'
:
True
,
'type'
:
'select'
,
},
{
'value'
:
'dvd'
,
'template_name'
:
'django/forms/widgets/select_option.html'
,
'label'
:
'DVD'
,
'attrs'
:
{},
'index'
:
'1_1'
,
'name'
:
'name'
,
'selected'
:
False
,
'type'
:
'select'
,
}]
)
self
.
assertEqual
(
index
,
1
)
label
,
options
,
index
=
unknown
self
.
assertEqual
(
label
,
None
)
self
.
assertEqual
(
options
,
[{
'value'
:
'unknown'
,
'selected'
:
False
,
'template_name'
:
'django/forms/widgets/select_option.html'
,
'label'
:
'Unknown'
,
'attrs'
:
{},
'index'
:
'2'
,
'name'
:
'name'
,
'type'
:
'select'
,
}]
)
self
.
assertEqual
(
index
,
2
)
def
test_deepcopy
(
self
):
def
test_deepcopy
(
self
):
"""
"""
...
...
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