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
4b2dcfe0
Kaydet (Commit)
4b2dcfe0
authored
Ara 29, 2015
tarafından
Chris Cogdon
Kaydeden (comit)
Tim Graham
Ara 30, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26006 -- Fixed incorrect object reference in SingleObjectMixin.get_context_object_name().
üst
7df9aa3a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
1 deletion
+30
-1
detail.py
django/views/generic/detail.py
+1
-1
1.9.1.txt
docs/releases/1.9.1.txt
+3
-0
test_detail.py
tests/generic_views/test_detail.py
+13
-0
urls.py
tests/generic_views/urls.py
+2
-0
views.py
tests/generic_views/views.py
+11
-0
No files found.
django/views/generic/detail.py
Dosyayı görüntüle @
4b2dcfe0
...
...
@@ -89,7 +89,7 @@ class SingleObjectMixin(ContextMixin):
if
self
.
context_object_name
:
return
self
.
context_object_name
elif
isinstance
(
obj
,
models
.
Model
):
if
self
.
object
.
_deferred
:
if
obj
.
_deferred
:
obj
=
obj
.
_meta
.
proxy_for_model
return
obj
.
_meta
.
model_name
else
:
...
...
docs/releases/1.9.1.txt
Dosyayı görüntüle @
4b2dcfe0
...
...
@@ -70,3 +70,6 @@ Bugfixes
* Fixed a regression in the admin which ignored line breaks in read-only fields
instead of converting them to ``<br>`` (:ticket:`25465`).
* Fixed incorrect object reference in
``SingleObjectMixin.get_context_object_name()`` (:ticket:`26006`).
tests/generic_views/test_detail.py
Dosyayı görüntüle @
4b2dcfe0
...
...
@@ -140,6 +140,19 @@ class DetailViewTest(TestCase):
self
.
assertNotIn
(
'author'
,
res
.
context
)
self
.
assertTemplateUsed
(
res
,
'generic_views/author_detail.html'
)
def
test_custom_detail
(
self
):
"""
AuthorCustomDetail overrides get() and ensures that
SingleObjectMixin.get_context_object_name() always uses the obj
parameter instead of self.object.
"""
res
=
self
.
client
.
get
(
'/detail/author/
%
s/custom_detail/'
%
self
.
author1
.
pk
)
self
.
assertEqual
(
res
.
status_code
,
200
)
self
.
assertEqual
(
res
.
context
[
'custom_author'
],
self
.
author1
)
self
.
assertNotIn
(
'author'
,
res
.
context
)
self
.
assertNotIn
(
'object'
,
res
.
context
)
self
.
assertTemplateUsed
(
res
,
'generic_views/author_detail.html'
)
def
test_deferred_queryset_template_name
(
self
):
class
FormContext
(
SingleObjectTemplateResponseMixin
):
request
=
RequestFactory
()
.
get
(
'/'
)
...
...
tests/generic_views/urls.py
Dosyayı görüntüle @
4b2dcfe0
...
...
@@ -50,6 +50,8 @@ urlpatterns = [
views
.
AuthorDetail
.
as_view
(
template_name
=
'generic_views/about.html'
)),
url
(
r'^detail/author/(?P<pk>[0-9]+)/context_object_name/$'
,
views
.
AuthorDetail
.
as_view
(
context_object_name
=
'thingy'
)),
url
(
r'^detail/author/(?P<pk>[0-9]+)/custom_detail/$'
,
views
.
AuthorCustomDetail
.
as_view
()),
url
(
r'^detail/author/(?P<pk>[0-9]+)/dupe_context_object_name/$'
,
views
.
AuthorDetail
.
as_view
(
context_object_name
=
'object'
)),
url
(
r'^detail/page/(?P<pk>[0-9]+)/field/$'
,
...
...
tests/generic_views/views.py
Dosyayı görüntüle @
4b2dcfe0
...
...
@@ -34,6 +34,17 @@ class AuthorDetail(generic.DetailView):
queryset
=
Author
.
objects
.
all
()
class
AuthorCustomDetail
(
generic
.
DetailView
):
template_name
=
'generic_views/author_detail.html'
queryset
=
Author
.
objects
.
all
()
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
# Ensures get_context_object_name() doesn't reference self.object.
author
=
self
.
get_object
()
context
=
{
'custom_'
+
self
.
get_context_object_name
(
author
):
author
}
return
self
.
render_to_response
(
context
)
class
PageDetail
(
generic
.
DetailView
):
queryset
=
Page
.
objects
.
all
()
template_name_field
=
'template'
...
...
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