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
f032bbc8
Kaydet (Commit)
f032bbc8
authored
Kas 07, 2016
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #18651 -- Removed assignment_tag per deprecation timeline.
üst
742d666d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
4 additions
and
82 deletions
+4
-82
library.py
django/template/library.py
+0
-10
custom-template-tags.txt
docs/howto/custom-template-tags.txt
+0
-29
1.9.txt
docs/releases/1.9.txt
+2
-3
2.0.txt
docs/releases/2.0.txt
+2
-0
custom.py
tests/template_tests/templatetags/custom.py
+0
-17
test_custom.py
tests/template_tests/test_custom.py
+0
-23
No files found.
django/template/library.py
Dosyayı görüntüle @
f032bbc8
import
functools
import
warnings
from
importlib
import
import_module
from
django.utils
import
six
from
django.utils.deprecation
import
RemovedInDjango20Warning
from
django.utils.html
import
conditional_escape
from
django.utils.inspect
import
getargspec
from
django.utils.itercompat
import
is_iterable
...
...
@@ -136,14 +134,6 @@ class Library(object):
else
:
raise
ValueError
(
"Invalid arguments provided to simple_tag"
)
def
assignment_tag
(
self
,
func
=
None
,
takes_context
=
None
,
name
=
None
):
warnings
.
warn
(
"assignment_tag() is deprecated. Use simple_tag() instead"
,
RemovedInDjango20Warning
,
stacklevel
=
2
,
)
return
self
.
simple_tag
(
func
,
takes_context
,
name
)
def
inclusion_tag
(
self
,
filename
,
func
=
None
,
takes_context
=
None
,
name
=
None
):
"""
Register a callable as an inclusion tag:
...
...
docs/howto/custom-template-tags.txt
Dosyayı görüntüle @
f032bbc8
...
...
@@ -629,35 +629,6 @@ positional arguments. For example:
{% my_tag 123 "abcd" book.title warning=message|lower profile=user.profile %}
Assignment tags
---------------
.. method:: django.template.Library.assignment_tag()
.. deprecated:: 1.9
``simple_tag`` can now store results in a template variable and should
be used instead.
To ease the creation of tags setting a variable in the context, Django provides
a helper function, ``assignment_tag``. This function works the same way as
:meth:`~django.template.Library.simple_tag` except that it stores the tag's
result in a specified context variable instead of directly outputting it.
Our earlier ``current_time`` function could thus be written like this::
@register.assignment_tag
def get_current_time(format_string):
return datetime.datetime.now().strftime(format_string)
You may then store the result in a template variable using the ``as`` argument
followed by the variable name, and output it yourself where you see fit:
.. code-block:: html+django
{% get_current_time "%Y-%m-%d %I:%M %p" as the_time %}
<p>The time is {{ the_time }}.</p>
Advanced custom template tags
-----------------------------
...
...
docs/releases/1.9.txt
Dosyayı görüntüle @
f032bbc8
...
...
@@ -938,9 +938,8 @@ define built-in libraries via the ``'builtins'`` key of :setting:`OPTIONS
In general, template tags do not autoescape their contents, and this behavior is
:ref:`documented <tags-auto-escaping>`. For tags like
:class:`~django.template.Library.inclusion_tag`, this is not a problem because
the included template will perform autoescaping. For
:class:`~django.template.Library.assignment_tag`, the output will be escaped
when it is used as a variable in the template.
the included template will perform autoescaping. For ``assignment_tag()``,
the output will be escaped when it is used as a variable in the template.
For the intended use cases of :class:`~django.template.Library.simple_tag`,
however, it is very easy to end up with incorrect HTML and possibly an XSS
...
...
docs/releases/2.0.txt
Dosyayı görüntüle @
f032bbc8
...
...
@@ -241,3 +241,5 @@ these features.
is removed.
* The ``django.forms.extras`` package is removed.
* The ``assignment_tag`` helper is removed.
tests/template_tests/templatetags/custom.py
Dosyayı görüntüle @
f032bbc8
import
operator
import
warnings
from
django
import
template
from
django.template.defaultfilters
import
stringfilter
...
...
@@ -168,19 +167,3 @@ def minustwo_overridden_name(value):
register
.
simple_tag
(
lambda
x
:
x
-
1
,
name
=
'minusone'
)
with
warnings
.
catch_warnings
():
warnings
.
simplefilter
(
'ignore'
)
@register.assignment_tag
def
assignment_no_params
():
"""Expected assignment_no_params __doc__"""
return
"assignment_no_params - Expected result"
assignment_no_params
.
anything
=
"Expected assignment_no_params __dict__"
@register.assignment_tag
(
takes_context
=
True
)
def
assignment_tag_without_context_parameter
(
arg
):
"""Expected assignment_tag_without_context_parameter __doc__"""
return
"Expected result"
assignment_tag_without_context_parameter
.
anything
=
"Expected assignment_tag_without_context_parameter __dict__"
tests/template_tests/test_custom.py
Dosyayı görüntüle @
f032bbc8
...
...
@@ -306,29 +306,6 @@ class InclusionTagTests(TagTestCase):
self
.
assertEqual
(
template
.
render
(
Context
({}))
.
strip
(),
'one
\n
two'
)
class
AssignmentTagTests
(
TagTestCase
):
def
test_assignment_tags
(
self
):
c
=
Context
({
'value'
:
42
})
t
=
self
.
engine
.
from_string
(
'{
%
load custom
%
}{
%
assignment_no_params as var
%
}The result is: {{ var }}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'The result is: assignment_no_params - Expected result'
)
def
test_assignment_tag_registration
(
self
):
# The decorators preserve the decorated function's docstring, name,
# and attributes.
self
.
verify_tag
(
custom
.
assignment_no_params
,
'assignment_no_params'
)
def
test_assignment_tag_missing_context
(
self
):
# The 'context' parameter must be present when takes_context is True
msg
=
(
"'assignment_tag_without_context_parameter' is decorated with "
"takes_context=True so it must have a first argument of 'context'"
)
with
self
.
assertRaisesMessage
(
TemplateSyntaxError
,
msg
):
self
.
engine
.
from_string
(
'{
%
load custom
%
}{
%
assignment_tag_without_context_parameter 123 as var
%
}'
)
class
TemplateTagLoadingTests
(
SimpleTestCase
):
@classmethod
...
...
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