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
51b606f7
Kaydet (Commit)
51b606f7
authored
Şub 19, 2015
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Removed a non-obvious side-effect of assigning Context.template.
Explicit is better than implicit.
üst
e43f99d1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
33 deletions
+38
-33
base.py
django/template/base.py
+5
-9
context.py
django/template/context.py
+33
-24
No files found.
django/template/base.py
Dosyayı görüntüle @
51b606f7
...
...
@@ -204,19 +204,15 @@ class Template(object):
def
render
(
self
,
context
):
"Display stage -- can be called many times"
# Set context.template to the original template -- as opposed to
# extended or included templates -- during rendering. This may be
# used for accessing context.template.engine.
toplevel_render
=
context
.
template
is
None
if
toplevel_render
:
context
.
template
=
self
context
.
render_context
.
push
()
try
:
return
self
.
_render
(
context
)
if
context
.
template
is
None
:
with
context
.
bind_template
(
self
):
return
self
.
_render
(
context
)
else
:
return
self
.
_render
(
context
)
finally
:
context
.
render_context
.
pop
()
if
toplevel_render
:
context
.
template
=
None
class
Token
(
object
):
...
...
django/template/context.py
Dosyayı görüntüle @
51b606f7
import
warnings
from
contextlib
import
contextmanager
from
copy
import
copy
from
django.utils.deprecation
import
RemovedInDjango20Warning
...
...
@@ -134,8 +135,8 @@ class Context(BaseContext):
self
.
use_l10n
=
use_l10n
self
.
use_tz
=
use_tz
self
.
render_context
=
RenderContext
()
# Set to the original template
during rendering -- as opposed to
#
extended or included templates
# Set to the original template
-- as opposed to extended or included
#
templates -- during rendering, see bind_template.
self
.
template
=
None
super
(
Context
,
self
)
.
__init__
(
dict_
)
...
...
@@ -143,6 +144,16 @@ class Context(BaseContext):
def
current_app
(
self
):
return
None
if
self
.
_current_app
is
_current_app_undefined
else
self
.
_current_app
@contextmanager
def
bind_template
(
self
,
template
):
if
self
.
template
is
not
None
:
raise
RuntimeError
(
"Context is already bound to a template"
)
self
.
template
=
template
try
:
yield
finally
:
self
.
template
=
None
def
__copy__
(
self
):
duplicate
=
super
(
Context
,
self
)
.
__copy__
()
duplicate
.
render_context
=
copy
(
self
.
render_context
)
...
...
@@ -210,28 +221,26 @@ class RequestContext(Context):
self
.
_processors_index
=
len
(
self
.
dicts
)
self
.
update
({})
# placeholder for context processors output
@property
def
template
(
self
):
return
self
.
_template
@template.setter
def
template
(
self
,
template
):
# Execute context processors when Template.render(self, context) sets
# context.template = self. Until then, since the context isn't tied to
# an engine, it has no way to know which context processors to apply.
self
.
_template
=
template
if
hasattr
(
self
,
'_processors_index'
):
if
template
is
None
:
# Unset context processors.
self
.
dicts
[
self
.
_processors_index
]
=
{}
else
:
# Set context processors for this engine.
processors
=
(
template
.
engine
.
template_context_processors
+
self
.
_processors
)
updates
=
{}
for
processor
in
processors
:
updates
.
update
(
processor
(
self
.
request
))
self
.
dicts
[
self
.
_processors_index
]
=
updates
@contextmanager
def
bind_template
(
self
,
template
):
if
self
.
template
is
not
None
:
raise
RuntimeError
(
"Context is already bound to a template"
)
self
.
template
=
template
# Set context processors according to the template engine's settings.
processors
=
(
template
.
engine
.
template_context_processors
+
self
.
_processors
)
updates
=
{}
for
processor
in
processors
:
updates
.
update
(
processor
(
self
.
request
))
self
.
dicts
[
self
.
_processors_index
]
=
updates
try
:
yield
finally
:
self
.
template
=
None
# Unset context processors.
self
.
dicts
[
self
.
_processors_index
]
=
{}
def
new
(
self
,
values
=
None
):
new_context
=
super
(
RequestContext
,
self
)
.
new
(
values
)
...
...
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