MCPcopy
hub / github.com/django/django / _text_words

Method _text_words

django/utils/text.py:251–261  ·  view source on GitHub ↗

Truncate a string after a certain number of words. Strip newlines in the string.

(self, length, truncate)

Source from the content-addressed store, hash-verified

249 return self._text_words(length, truncate)
250
251 def _text_words(self, length, truncate):
252 """
253 Truncate a string after a certain number of words.
254
255 Strip newlines in the string.
256 """
257 words = self._wrapped.split()
258 if len(words) > length:
259 words = words[:length]
260 return add_truncation_text(" ".join(words), truncate)
261 return " ".join(words)
262
263
264@keep_lazy_text

Callers 1

wordsMethod · 0.95

Calls 3

add_truncation_textFunction · 0.85
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected