~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to django/utils/text.py

  • Committer: Bazaar Package Importer
  • Author(s): Raphaël Hertzog
  • Date: 2010-09-18 19:37:03 UTC
  • mto: (1.1.12 upstream) (4.4.9 sid)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: james.westby@ubuntu.com-20100918193703-sw44inm7dnu8mf42
Import upstream version 1.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
def truncate_words(s, num, end_text='...'):
40
40
    """Truncates a string after a certain number of words. Takes an optional
41
41
    argument of what should be used to notify that the string has been
42
 
    truncated, defaults to ellipsis (...)"""
 
42
    truncated, defaulting to ellipsis (...)
 
43
 
 
44
    Newlines in the string will be stripped.
 
45
    """
43
46
    s = force_unicode(s)
44
47
    length = int(num)
45
48
    words = s.split()
51
54
truncate_words = allow_lazy(truncate_words, unicode)
52
55
 
53
56
def truncate_html_words(s, num, end_text='...'):
54
 
    """Truncates html to a certain number of words (not counting tags and
 
57
    """Truncates HTML to a certain number of words (not counting tags and
55
58
    comments). Closes opened tags if they were correctly closed in the given
56
59
    html. Takes an optional argument of what should be used to notify that the
57
 
    string has been truncated, defaults to ellipsis (...)."""
 
60
    string has been truncated, defaulting to ellipsis (...).
 
61
 
 
62
    Newlines in the HTML are preserved.
 
63
    """
58
64
    s = force_unicode(s)
59
65
    length = int(num)
60
66
    if length <= 0: