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
75bc5bc6
Kaydet (Commit)
75bc5bc6
authored
Nis 13, 2015
tarafından
Craig Oldford
Kaydeden (comit)
Tim Graham
Nis 14, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #12199 -- Added the ability to use "as" with the firstof template tag.
üst
6023312d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
4 deletions
+31
-4
defaulttags.py
django/template/defaulttags.py
+14
-4
builtins.txt
docs/ref/templates/builtins.txt
+7
-0
1.9.txt
docs/releases/1.9.txt
+3
-0
test_firstof.py
tests/template_tests/syntax_tests/test_firstof.py
+7
-0
No files found.
django/template/defaulttags.py
Dosyayı görüntüle @
75bc5bc6
...
...
@@ -110,14 +110,19 @@ class FilterNode(Node):
class
FirstOfNode
(
Node
):
def
__init__
(
self
,
variables
):
def
__init__
(
self
,
variables
,
asvar
=
None
):
self
.
vars
=
variables
self
.
asvar
=
asvar
def
render
(
self
,
context
):
for
var
in
self
.
vars
:
value
=
var
.
resolve
(
context
,
True
)
if
value
:
return
render_value_in_context
(
value
,
context
)
first
=
render_value_in_context
(
value
,
context
)
if
self
.
asvar
:
context
[
self
.
asvar
]
=
first
return
''
return
first
return
''
...
...
@@ -748,7 +753,7 @@ def firstof(parser, token):
Sample usage::
{
%
firstof var1 var2 var3
%
}
{
%
firstof var1 var2 var3
as myvar
%
}
This is equivalent to::
...
...
@@ -779,9 +784,14 @@ def firstof(parser, token):
"""
bits
=
token
.
split_contents
()[
1
:]
asvar
=
None
if
len
(
bits
)
<
1
:
raise
TemplateSyntaxError
(
"'firstof' statement requires at least one argument"
)
return
FirstOfNode
([
parser
.
compile_filter
(
bit
)
for
bit
in
bits
])
if
len
(
bits
)
>=
2
and
bits
[
-
2
]
==
'as'
:
asvar
=
bits
[
-
1
]
bits
=
bits
[:
-
2
]
return
FirstOfNode
([
parser
.
compile_filter
(
bit
)
for
bit
in
bits
],
asvar
)
@register.tag
(
'for'
)
...
...
docs/ref/templates/builtins.txt
Dosyayı görüntüle @
75bc5bc6
...
...
@@ -285,6 +285,13 @@ Or if only some variables should be escaped, you can use::
{% firstof var1 var2|safe var3 "<strong>fallback value</strong>"|safe %}
You can use the syntax ``{% firstof var1 var2 var3 as value %}`` to store the
output inside a variable.
.. versionadded:: 1.9
The "as" syntax was added.
.. templatetag:: for
for
...
...
docs/releases/1.9.txt
Dosyayı görüntüle @
75bc5bc6
...
...
@@ -208,6 +208,9 @@ Templates
* A warning will now be logged for missing context variables. These messages
will be logged to the :ref:`django.template <django-template-logger>` logger.
* The :ttag:`firstof` template tag supports storing the output in a variable
using 'as'.
Requests and Responses
^^^^^^^^^^^^^^^^^^^^^^
...
...
tests/template_tests/syntax_tests/test_firstof.py
Dosyayı görüntüle @
75bc5bc6
...
...
@@ -81,3 +81,10 @@ class FirstOfTagTests(SimpleTestCase):
def
test_firstof14
(
self
):
output
=
self
.
engine
.
render_to_string
(
'firstof14'
,
{
'a'
:
'<'
})
self
.
assertEqual
(
output
,
'<'
)
@setup
({
'firstof15'
:
'{
%
firstof a b c as myvar
%
}'
})
def
test_firstof15
(
self
):
ctx
=
{
'a'
:
0
,
'b'
:
2
,
'c'
:
3
}
output
=
self
.
engine
.
render_to_string
(
'firstof15'
,
ctx
)
self
.
assertEqual
(
ctx
[
'myvar'
],
'2'
)
self
.
assertEqual
(
output
,
''
)
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