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
002fe076
Kaydet (Commit)
002fe076
authored
Nis 04, 2017
tarafından
kapil garg
Kaydeden (comit)
Tim Graham
Nis 04, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27974 -- Kept resolved templates constant during one rendering cycle.
Thanks Florian Apolloner for the initial patch.
üst
ef8a339d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
1 deletion
+47
-1
loader_tags.py
django/template/loader_tags.py
+1
-1
test_if_changed.py
tests/template_tests/syntax_tests/test_if_changed.py
+11
-0
test_include.py
tests/template_tests/syntax_tests/test_include.py
+20
-0
custom.py
tests/template_tests/templatetags/custom.py
+15
-0
No files found.
django/template/loader_tags.py
Dosyayı görüntüle @
002fe076
...
...
@@ -176,7 +176,7 @@ class IncludeNode(Node):
if
not
callable
(
getattr
(
template
,
'render'
,
None
)):
# If not, we'll try our cache, and get_template()
template_name
=
template
cache
=
context
.
render_context
.
setdefault
(
self
.
context_key
,
{})
cache
=
context
.
render_context
.
dicts
[
0
]
.
setdefault
(
self
,
{})
template
=
cache
.
get
(
template_name
)
if
template
is
None
:
template
=
context
.
template
.
engine
.
get_template
(
template_name
)
...
...
tests/template_tests/syntax_tests/test_if_changed.py
Dosyayı görüntüle @
002fe076
...
...
@@ -212,3 +212,14 @@ class IfChangedTests(SimpleTestCase):
])
output
=
engine
.
render_to_string
(
'template'
,
dict
(
vars
=
[
1
,
1
,
2
,
2
,
3
,
3
]))
self
.
assertEqual
(
output
,
"123"
)
def
test_include_state
(
self
):
"""Tests the node state for different IncludeNodes (#27974)."""
engine
=
Engine
(
loaders
=
[
(
'django.template.loaders.locmem.Loader'
,
{
'template'
:
'{
%
for x in vars
%
}{
%
include "include"
%
}{
%
include "include"
%
}{
%
endfor
%
}'
,
'include'
:
'{
%
ifchanged
%
}{{ x }}{
%
endifchanged
%
}'
,
}),
])
output
=
engine
.
render_to_string
(
'template'
,
dict
(
vars
=
[
1
,
1
,
2
,
2
,
3
,
3
]))
self
.
assertEqual
(
output
,
'112233'
)
tests/template_tests/syntax_tests/test_include.py
Dosyayı görüntüle @
002fe076
...
...
@@ -308,3 +308,23 @@ class IncludeTests(SimpleTestCase):
"Recursion! A1 Recursion! B1 B2 B3 Recursion! C1"
,
t
.
render
(
Context
({
'comments'
:
comments
}))
.
replace
(
' '
,
''
)
.
replace
(
'
\n
'
,
' '
)
.
strip
(),
)
def
test_include_cache
(
self
):
"""
{
%
include
%
} keeps resolved templates constant (#27974). The
CounterNode object in the {
%
counter
%
} template tag is created once
if caching works properly. Each iteration increases the counter instead
of restarting it.
This works as a regression test only if the cached loader
isn't used, so the @setup decorator isn't used.
"""
engine
=
Engine
(
loaders
=
[
(
'django.template.loaders.locmem.Loader'
,
{
'template'
:
'{
%
for x in vars
%
}{
%
include "include"
%
}{
%
endfor
%
}'
,
'include'
:
'{
%
include "next"
%
}'
,
'next'
:
'{
%
load custom
%
}{
%
counter
%
}'
}),
],
libraries
=
{
'custom'
:
'template_tests.templatetags.custom'
})
output
=
engine
.
render_to_string
(
'template'
,
dict
(
vars
=
range
(
9
)))
self
.
assertEqual
(
output
,
'012345678'
)
tests/template_tests/templatetags/custom.py
Dosyayı görüntüle @
002fe076
...
...
@@ -166,3 +166,18 @@ def minustwo_overridden_name(value):
register
.
simple_tag
(
lambda
x
:
x
-
1
,
name
=
'minusone'
)
@register.tag
(
'counter'
)
def
counter
(
parser
,
token
):
return
CounterNode
()
class
CounterNode
(
template
.
Node
):
def
__init__
(
self
):
self
.
count
=
0
def
render
(
self
,
context
):
count
=
self
.
count
self
.
count
=
count
+
1
return
count
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