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
68b540c9
Kaydet (Commit)
68b540c9
authored
Kas 09, 2013
tarafından
Vajrasky Kok
Kaydeden (comit)
Anssi Kääriäinen
Kas 19, 2013
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21361 -- allowed access self.value() from SimpleListFilter lookup
Reviewed by Chris Medrela.
üst
4fdd51b7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
3 deletions
+40
-3
filters.py
django/contrib/admin/filters.py
+3
-3
tests.py
tests/admin_filters/tests.py
+37
-0
No files found.
django/contrib/admin/filters.py
Dosyayı görüntüle @
68b540c9
...
...
@@ -67,13 +67,13 @@ class SimpleListFilter(ListFilter):
raise
ImproperlyConfigured
(
"The list filter '
%
s' does not specify "
"a 'parameter_name'."
%
self
.
__class__
.
__name__
)
if
self
.
parameter_name
in
params
:
value
=
params
.
pop
(
self
.
parameter_name
)
self
.
used_parameters
[
self
.
parameter_name
]
=
value
lookup_choices
=
self
.
lookups
(
request
,
model_admin
)
if
lookup_choices
is
None
:
lookup_choices
=
()
self
.
lookup_choices
=
list
(
lookup_choices
)
if
self
.
parameter_name
in
params
:
value
=
params
.
pop
(
self
.
parameter_name
)
self
.
used_parameters
[
self
.
parameter_name
]
=
value
def
has_output
(
self
):
return
len
(
self
.
lookup_choices
)
>
0
...
...
tests/admin_filters/tests.py
Dosyayı görüntüle @
68b540c9
...
...
@@ -106,6 +106,17 @@ class DepartmentListFilterLookupWithUnderscoredParameter(DepartmentListFilterLoo
parameter_name
=
'department__whatever'
class
DepartmentListFilterLookupWithDynamicValue
(
DecadeListFilterWithTitleAndParameter
):
def
lookups
(
self
,
request
,
model_admin
):
if
self
.
value
()
==
'the 80s'
:
return
((
'the 90s'
,
"the 1990's"
),)
elif
self
.
value
()
==
'the 90s'
:
return
((
'the 80s'
,
"the 1980's"
),)
else
:
return
((
'the 80s'
,
"the 1980's"
),
(
'the 90s'
,
"the 1990's"
),)
class
CustomUserAdmin
(
UserAdmin
):
list_filter
=
(
'books_authored'
,
'books_contributed'
)
...
...
@@ -169,6 +180,10 @@ class DepartmentFilterUnderscoredEmployeeAdmin(EmployeeAdmin):
list_filter
=
[
DepartmentListFilterLookupWithUnderscoredParameter
,
]
class
DepartmentFilterDynamicValueBookAdmin
(
EmployeeAdmin
):
list_filter
=
[
DepartmentListFilterLookupWithDynamicValue
,
]
class
ListFiltersTests
(
TestCase
):
def
setUp
(
self
):
...
...
@@ -816,3 +831,25 @@ class ListFiltersTests(TestCase):
self
.
assertEqual
(
choices
[
2
][
'display'
],
'Design'
)
self
.
assertEqual
(
choices
[
2
][
'selected'
],
False
)
self
.
assertEqual
(
choices
[
2
][
'query_string'
],
'?department__code__exact=DSN'
)
def
test_lookup_with_dynamic_value
(
self
):
"""
Ensure SimpleListFilter can access self.value() inside the lookup.
"""
modeladmin
=
DepartmentFilterDynamicValueBookAdmin
(
Book
,
site
)
def
_test_choices
(
request
,
expected_displays
):
changelist
=
self
.
get_changelist
(
request
,
Book
,
modeladmin
)
filterspec
=
changelist
.
get_filters
(
request
)[
0
][
0
]
self
.
assertEqual
(
force_text
(
filterspec
.
title
),
'publication decade'
)
choices
=
tuple
(
c
[
'display'
]
for
c
in
filterspec
.
choices
(
changelist
))
self
.
assertEqual
(
choices
,
expected_displays
)
_test_choices
(
self
.
request_factory
.
get
(
'/'
,
{}),
(
"All"
,
"the 1980's"
,
"the 1990's"
))
_test_choices
(
self
.
request_factory
.
get
(
'/'
,
{
'publication-decade'
:
'the 80s'
}),
(
"All"
,
"the 1990's"
))
_test_choices
(
self
.
request_factory
.
get
(
'/'
,
{
'publication-decade'
:
'the 90s'
}),
(
"All"
,
"the 1980's"
))
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