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
3bbebd06
Kaydet (Commit)
3bbebd06
authored
Agu 18, 2015
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #13408 -- Made unpacking mismatch an exception in {% for %} tag per deprecation timeline.
üst
1392aff4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
38 deletions
+20
-38
defaulttags.py
django/template/defaulttags.py
+2
-4
test_for.py
tests/template_tests/syntax_tests/test_for.py
+18
-34
No files found.
django/template/defaulttags.py
Dosyayı görüntüle @
3bbebd06
...
...
@@ -9,7 +9,6 @@ from itertools import cycle as itertools_cycle, groupby
from
django.conf
import
settings
from
django.utils
import
six
,
timezone
from
django.utils.deprecation
import
RemovedInDjango110Warning
from
django.utils.encoding
import
force_text
,
smart_text
from
django.utils.html
import
conditional_escape
,
format_html
from
django.utils.lorem_ipsum
import
paragraphs
,
words
...
...
@@ -200,11 +199,10 @@ class ForNode(Node):
len_item
=
len
(
item
)
# Check loop variable count before unpacking
if
num_loopvars
!=
len_item
:
warnings
.
warn
(
raise
ValueError
(
"Need {} values to unpack in for loop; got {}. "
"This will raise an exception in Django 1.10."
.
format
(
num_loopvars
,
len_item
),
RemovedInDjango110Warning
)
)
try
:
unpacked_vars
=
dict
(
zip
(
self
.
loopvars
,
item
))
except
TypeError
:
...
...
tests/template_tests/syntax_tests/test_for.py
Dosyayı görüntüle @
3bbebd06
from
django.template
import
TemplateSyntaxError
from
django.test
import
SimpleTestCase
,
ignore_warnings
from
django.utils.deprecation
import
RemovedInDjango110Warning
from
django.test
import
SimpleTestCase
from
..utils
import
setup
...
...
@@ -130,46 +129,31 @@ class ForTagTests(SimpleTestCase):
# These tests raise deprecation warnings and will raise an exception
# in Django 1.10. The existing behavior is silent truncation if the
# length of loopvars differs to the length of each set of items.
@ignore_warnings
(
category
=
RemovedInDjango110Warning
)
@setup
({
'for-tag-unpack10'
:
'{
%
for x,y in items
%
}{{ x }}:{{ y }}/{
%
endfor
%
}'
})
def
test_for_tag_unpack10
(
self
):
output
=
self
.
engine
.
render_to_string
(
'for-tag-unpack10'
,
{
'items'
:
((
'one'
,
1
,
'carrot'
),
(
'two'
,
2
,
'orange'
))}
,
)
self
.
assertEqual
(
output
,
'one:1/two:2/'
)
with
self
.
assertRaisesMessage
(
ValueError
,
'Need 2 values to unpack in for loop; got 3.'
):
self
.
engine
.
render_to_string
(
'for-tag-unpack10'
,
{
'items'
:
((
'one'
,
1
,
'carrot'
),
(
'two'
,
2
,
'orange'
))},
)
@ignore_warnings
(
category
=
RemovedInDjango110Warning
)
@setup
({
'for-tag-unpack11'
:
'{
%
for x,y,z in items
%
}{{ x }}:{{ y }},{{ z }}/{
%
endfor
%
}'
})
def
test_for_tag_unpack11
(
self
):
output
=
self
.
engine
.
render_to_string
(
'for-tag-unpack11'
,
{
'items'
:
((
'one'
,
1
),
(
'two'
,
2
))},
)
if
self
.
engine
.
string_if_invalid
:
self
.
assertEqual
(
output
,
'one:1,INVALID/two:2,INVALID/'
)
else
:
self
.
assertEqual
(
output
,
'one:1,/two:2,/'
)
with
self
.
assertRaisesMessage
(
ValueError
,
'Need 3 values to unpack in for loop; got 2.'
):
self
.
engine
.
render_to_string
(
'for-tag-unpack11'
,
{
'items'
:
((
'one'
,
1
),
(
'two'
,
2
))},
)
@ignore_warnings
(
category
=
RemovedInDjango110Warning
)
@setup
({
'for-tag-unpack12'
:
'{
%
for x,y,z in items
%
}{{ x }}:{{ y }},{{ z }}/{
%
endfor
%
}'
})
def
test_for_tag_unpack12
(
self
):
output
=
self
.
engine
.
render_to_string
(
'for-tag-unpack12'
,
{
'items'
:
((
'one'
,
1
,
'carrot'
),
(
'two'
,
2
))}
)
if
self
.
engine
.
string_if_invalid
:
self
.
assertEqual
(
output
,
'one:1,carrot/two:2,INVALID/'
)
else
:
self
.
assertEqual
(
output
,
'one:1,carrot/two:2,/'
)
with
self
.
assertRaisesMessage
(
ValueError
,
'Need 3 values to unpack in for loop; got 2.'
):
self
.
engine
.
render_to_string
(
'for-tag-unpack12'
,
{
'items'
:
((
'one'
,
1
,
'carrot'
),
(
'two'
,
2
))}
)
@ignore_warnings
(
category
=
RemovedInDjango110Warning
)
@setup
({
'for-tag-unpack14'
:
'{
%
for x,y in items
%
}{{ x }}:{{ y }}/{
%
endfor
%
}'
})
def
test_for_tag_unpack14
(
self
):
output
=
self
.
engine
.
render_to_string
(
'for-tag-unpack14'
,
{
'items'
:
(
1
,
2
)})
if
self
.
engine
.
string_if_invalid
:
self
.
assertEqual
(
output
,
'INVALID:INVALID/INVALID:INVALID/'
)
else
:
self
.
assertEqual
(
output
,
':/:/'
)
with
self
.
assertRaisesMessage
(
ValueError
,
'Need 2 values to unpack in for loop; got 1.'
):
self
.
engine
.
render_to_string
(
'for-tag-unpack14'
,
{
'items'
:
(
1
,
2
)})
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