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
2ccfac1a
Kaydet (Commit)
2ccfac1a
authored
Eyl 05, 2015
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #23913 -- Removed support for a single equals sign in {% if %} tag.
Per deprecation timeline.
üst
9af3c6b9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
56 deletions
+7
-56
smartif.py
django/template/smartif.py
+1
-12
test_if.py
tests/template_tests/syntax_tests/test_if.py
+6
-44
No files found.
django/template/smartif.py
Dosyayı görüntüle @
2ccfac1a
"""
Parser and utilities for the smart 'if' tag
"""
import
warnings
from
django.utils.deprecation
import
RemovedInDjango110Warning
# Using a simple top down parser, as described here:
# http://effbot.org/zone/simple-top-down-parsing.htm.
# 'led' = left denotation
# 'nud' = null denotation
# 'bp' = binding power (left = lbp, right = rbp)
class
TokenBase
(
object
):
"""
Base class for operators and literals, mainly for debugging and for throwing
...
...
@@ -102,8 +98,6 @@ OPERATORS = {
'not'
:
prefix
(
8
,
lambda
context
,
x
:
not
x
.
eval
(
context
)),
'in'
:
infix
(
9
,
lambda
context
,
x
,
y
:
x
.
eval
(
context
)
in
y
.
eval
(
context
)),
'not in'
:
infix
(
9
,
lambda
context
,
x
,
y
:
x
.
eval
(
context
)
not
in
y
.
eval
(
context
)),
# This should be removed in Django 1.10:
'='
:
infix
(
10
,
lambda
context
,
x
,
y
:
x
.
eval
(
context
)
==
y
.
eval
(
context
)),
'=='
:
infix
(
10
,
lambda
context
,
x
,
y
:
x
.
eval
(
context
)
==
y
.
eval
(
context
)),
'!='
:
infix
(
10
,
lambda
context
,
x
,
y
:
x
.
eval
(
context
)
!=
y
.
eval
(
context
)),
'>'
:
infix
(
10
,
lambda
context
,
x
,
y
:
x
.
eval
(
context
)
>
y
.
eval
(
context
)),
...
...
@@ -178,11 +172,6 @@ class IfParser(object):
except
(
KeyError
,
TypeError
):
return
self
.
create_var
(
token
)
else
:
if
token
==
'='
:
warnings
.
warn
(
"Operator '=' is deprecated and will be removed in Django 1.10. Use '==' instead."
,
RemovedInDjango110Warning
,
stacklevel
=
2
)
return
op
()
def
next_token
(
self
):
...
...
tests/template_tests/syntax_tests/test_if.py
Dosyayı görüntüle @
2ccfac1a
import
warnings
from
django.template
import
TemplateSyntaxError
from
django.test
import
SimpleTestCase
,
ignore_warnings
from
django.test.utils
import
reset_warning_registry
from
django.utils.deprecation
import
RemovedInDjango110Warning
from
django.test
import
SimpleTestCase
from
..utils
import
TestObj
,
setup
...
...
@@ -526,42 +522,8 @@ class IfTagTests(SimpleTestCase):
output
=
self
.
engine
.
render_to_string
(
'if-tag-badarg04'
)
self
.
assertEqual
(
output
,
'no'
)
@setup
({
'if-tag-eq-deprecated'
:
'{
%
if foo = bar
%
}yes{
%
else
%
}no{
%
endif
%
}'
},
test_once
=
True
)
def
test_if_tag_eq_deprecated
(
self
):
reset_warning_registry
()
with
warnings
.
catch_warnings
(
record
=
True
)
as
warns
:
warnings
.
simplefilter
(
'always'
)
output
=
self
.
engine
.
render_to_string
(
'if-tag-eq-deprecated'
)
self
.
assertEqual
(
output
,
'yes'
)
self
.
assertEqual
(
len
(
warns
),
1
)
self
.
assertEqual
(
str
(
warns
[
0
]
.
message
),
"Operator '=' is deprecated and will be removed in Django 1.10. "
"Use '==' instead."
)
@ignore_warnings
(
category
=
RemovedInDjango110Warning
)
class
TestEqualitySingleEqualsSign
(
SimpleTestCase
):
# The following tests should be changed to template.TemplateSyntaxError
# (or simply removed) when the deprecation path ends in Django 1.10.
@setup
({
'if-tag-eq01'
:
'{
%
if foo = bar
%
}yes{
%
else
%
}no{
%
endif
%
}'
})
def
test_if_tag_eq01
(
self
):
output
=
self
.
engine
.
render_to_string
(
'if-tag-eq01'
,
{
'foo'
:
1
})
self
.
assertEqual
(
output
,
'no'
)
@setup
({
'if-tag-eq02'
:
'{
%
if foo = bar
%
}yes{
%
else
%
}no{
%
endif
%
}'
})
def
test_if_tag_eq02
(
self
):
output
=
self
.
engine
.
render_to_string
(
'if-tag-eq02'
,
{
'foo'
:
1
,
'bar'
:
1
})
self
.
assertEqual
(
output
,
'yes'
)
@setup
({
'if-tag-eq03'
:
'{
%
if foo = bar
%
}yes{
%
else
%
}no{
%
endif
%
}'
})
def
test_if_tag_eq03
(
self
):
output
=
self
.
engine
.
render_to_string
(
'if-tag-eq03'
,
{
'foo'
:
1
,
'bar'
:
2
})
self
.
assertEqual
(
output
,
'no'
)
@setup
({
'if-tag-eq04'
:
'{
%
if foo ==
\'\'
%
}yes{
%
else
%
}no{
%
endif
%
}'
})
def
test_if_tag_eq04
(
self
):
output
=
self
.
engine
.
render_to_string
(
'if-tag-eq04'
)
self
.
assertEqual
(
output
,
'no'
)
@setup
({
'if-tag-single-eq'
:
'{
%
if foo = bar
%
}yes{
%
else
%
}no{
%
endif
%
}'
})
def
test_if_tag_single_eq
(
self
):
# A single equals sign is a syntax error.
with
self
.
assertRaises
(
TemplateSyntaxError
):
self
.
engine
.
render_to_string
(
'if-tag-single-eq'
,
{
'foo'
:
1
})
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