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
388e79e9
Kaydet (Commit)
388e79e9
authored
Mar 11, 2015
tarafından
Preston Timmons
Kaydeden (comit)
Tim Graham
Mar 16, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24493 -- Added BaseContext.setdefault()
üst
4d941409
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
0 deletions
+28
-0
context.py
django/template/context.py
+7
-0
api.txt
docs/ref/templates/api.txt
+7
-0
1.9.txt
docs/releases/1.9.txt
+3
-0
test_context.py
tests/template_tests/test_context.py
+11
-0
No files found.
django/template/context.py
Dosyayı görüntüle @
388e79e9
...
...
@@ -89,6 +89,13 @@ class BaseContext(object):
return
d
[
key
]
return
otherwise
def
setdefault
(
self
,
key
,
default
=
None
):
try
:
return
self
[
key
]
except
KeyError
:
self
[
key
]
=
default
return
default
def
new
(
self
,
values
=
None
):
"""
Returns a new context with the same properties, but with only the
...
...
docs/ref/templates/api.txt
Dosyayı görüntüle @
388e79e9
...
...
@@ -420,6 +420,13 @@ dictionary syntax::
Returns the value for ``key`` if ``key`` is in the context, else returns
``otherwise``.
.. method:: Context.setdefault(key, default=None)
.. versionadded:: 1.9
If ``key`` is in the context, returns its value. Otherwise inserts ``key``
with a value of ``default`` and returns ``default``.
.. method:: Context.pop()
.. method:: Context.push()
.. exception:: ContextPopException
...
...
docs/releases/1.9.txt
Dosyayı görüntüle @
388e79e9
...
...
@@ -166,6 +166,9 @@ Templates
helper can now store results in a template variable by using the ``as``
argument.
* Added a :meth:`Context.setdefault() <django.template.Context.setdefault>`
method.
Requests and Responses
^^^^^^^^^^^^^^^^^^^^^^
...
...
tests/template_tests/test_context.py
Dosyayı görüntüle @
388e79e9
...
...
@@ -30,6 +30,17 @@ class ContextTests(SimpleTestCase):
self
.
assertEqual
(
c
[
'a'
],
3
)
self
.
assertEqual
(
c
[
'a'
],
1
)
def
test_setdefault
(
self
):
c
=
Context
()
x
=
c
.
setdefault
(
'x'
,
42
)
self
.
assertEqual
(
x
,
42
)
self
.
assertEqual
(
c
[
'x'
],
42
)
x
=
c
.
setdefault
(
'x'
,
100
)
self
.
assertEqual
(
x
,
42
)
self
.
assertEqual
(
c
[
'x'
],
42
)
def
test_resolve_on_context_method
(
self
):
"""
#17778 -- Variable shouldn't resolve RequestContext methods
...
...
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