1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #5025 -- Add a "truncatechars" template filter. Many thanks to Chris Beaven.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16542 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel
2011-07-14 13:47:10 +00:00
parent 12b7c2a702
commit 3b77458371
7 changed files with 281 additions and 86 deletions

View File

@@ -220,6 +220,12 @@ their deprecation, as per the :ref:`Django deprecation policy
was deprecated since Django 1.4 and will be removed in favor of the
generic static files handling.
* The builin truncation functions
:func:`django.utils.text.truncate_words` and
:func:`django.utils.text.truncate_html_words`
were deprecated since Django 1.4 and will be removed in favor
of the ``django.utils.text.Truncator`` class.
* 2.0
* ``django.views.defaults.shortcut()``. This function has been moved
to ``django.contrib.contenttypes.views.shortcut()`` as part of the

View File

@@ -2055,6 +2055,24 @@ For example::
If ``value`` is ``"my first post"``, the output will be ``"My First Post"``.
.. templatefilter:: truncatechars
truncatechars
^^^^^^^^^^^^^
.. versionadded:: 1.4
Truncates a string if it is longer than the specified number of characters.
Truncated strings will end with a translatable ellipsis sequence ("...").
**Argument:** Number of characters to truncate to
For example::
{{ value|truncatechars:9 }}
If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel i..."``.
.. templatefilter:: truncatewords
truncatewords

View File

@@ -145,6 +145,14 @@ A new helper function,
``template.Library`` to ease the creation of template tags that store some
data in a specified context variable.
``truncatechars`` template filter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Added a filter which truncates a string to be no longer than the specified
number of characters. Truncated strings end with a translatable ellipsis
sequence ("..."). See the :tfilter:`truncatechars docs <truncatechars>` for
more details.
CSRF improvements
~~~~~~~~~~~~~~~~~