class documentation

class Truncator(SimpleLazyObject):

View In Hierarchy

An object used to truncate text, either by characters or words.
Method __init__ Pass in a callable that returns the object to be wrapped.
Method ​_text​_chars Truncate a string after a certain number of chars.
Method ​_text​_words Truncate a string after a certain number of words.
Method ​_truncate​_html Truncate HTML to a certain number of chars (not counting tags and comments), or, if words is True, then to a certain number of words. Close opened tags if they were correctly closed in the given HTML.
Method add​_truncation​_text Undocumented
Method chars Return the text truncated to be no longer than the specified number of characters.
Method words Truncate a string after a certain number of words. truncate specifies what should be used to notify that the string has been truncated, defaulting to ellipsis.

Inherited from SimpleLazyObject:

Method __copy__ Undocumented
Method __deepcopy__ Undocumented
Method __repr__ Undocumented
Method ​_setup Must be implemented by subclasses to initialize the wrapped object.
Instance Variable ​_wrapped Undocumented

Inherited from LazyObject (via SimpleLazyObject):

Method __delattr__ Undocumented
Method __reduce__ Undocumented
Method __setattr__ Undocumented
Class Variable __bool__ Undocumented
Class Variable __bytes__ Undocumented
Class Variable __class__ Undocumented
Class Variable __contains__ Undocumented
Class Variable __delitem__ Undocumented
Class Variable __dir__ Undocumented
Class Variable __eq__ Undocumented
Class Variable __getattr__ Undocumented
Class Variable __getitem__ Undocumented
Class Variable __gt__ Undocumented
Class Variable __hash__ Undocumented
Class Variable __iter__ Undocumented
Class Variable __len__ Undocumented
Class Variable __lt__ Undocumented
Class Variable __ne__ Undocumented
Class Variable __setitem__ Undocumented
Class Variable __str__ Undocumented
def __init__(self, text):

Pass in a callable that returns the object to be wrapped.

If copies are made of the resulting SimpleLazyObject, which can happen in various circumstances within Django, then you must ensure that the callable can be safely run more than once and will return the same value.

def _text_chars(self, length, truncate, text, truncate_len):
Truncate a string after a certain number of chars.
def _text_words(self, length, truncate):

Truncate a string after a certain number of words.

Strip newlines in the string.

def _truncate_html(self, length, truncate, text, truncate_len, words):

Truncate HTML to a certain number of chars (not counting tags and comments), or, if words is True, then to a certain number of words. Close opened tags if they were correctly closed in the given HTML.

Preserve newlines in the HTML.

def add_truncation_text(self, text, truncate=None):

Undocumented

def chars(self, num, truncate=None, html=False):

Return the text truncated to be no longer than the specified number of characters.

truncate specifies what should be used to notify that the string has been truncated, defaulting to a translatable string of an ellipsis.

def words(self, num, truncate=None, html=False):
Truncate a string after a certain number of words. truncate specifies what should be used to notify that the string has been truncated, defaulting to ellipsis.