def clean_biography(self): value = self.cleaned_data["biography"] words = wordcount(value) if words > 100: raise ValidationError(_(u"Please limit speaker biography to 100 " u"words or less")) return value
def control_trunc(value, max_words): if BLOG['truncater'] in value: return value[:value.find(BLOG['truncater'])] if wordcount(value) > max_words : return truncate_html_words(value, max_words) else: return value
def test_non_string_input(self): # Filters shouldn't break if passed non-strings self.assertEqual(addslashes(123), '123') self.assertEqual(linenumbers(123), '1. 123') self.assertEqual(lower(123), '123') self.assertEqual(make_list(123), ['1', '2', '3']) self.assertEqual(slugify(123), '123') self.assertEqual(title(123), '123') self.assertEqual(truncatewords(123, 2), '123') self.assertEqual(upper(123), '123') self.assertEqual(urlencode(123), '123') self.assertEqual(urlize(123), '123') self.assertEqual(urlizetrunc(123, 1), '123') self.assertEqual(wordcount(123), 1) self.assertEqual(wordwrap(123, 2), '123') self.assertEqual(ljust('123', 4), '123 ') self.assertEqual(rjust('123', 4), ' 123') self.assertEqual(center('123', 5), ' 123 ') self.assertEqual(center('123', 6), ' 123 ') self.assertEqual(cut(123, '2'), '13') self.assertEqual(escape(123), '123') self.assertEqual(linebreaks_filter(123), '<p>123</p>') self.assertEqual(linebreaksbr(123), '123') self.assertEqual(removetags(123, 'a'), '123') self.assertEqual(striptags(123), '123')
def save(self, *args, **kwargs): self.content_length = len(self.content) content = re.sub('[!-@[-`]', ' ', self.content) content = re.sub(' +', ' ', self.content) self.content_word_count = wordcount(content) self.content_ascii = unicode_to_ascii(self.content) self.subject_title_ascii = unicode_to_ascii(self.subject_title) super(ScrappedDocument, self).save(*args, **kwargs)
def make_post(post, turncate=False): if turncate: turncate = int(turncate) if wordcount(post.body_html) >= turncate: post.body_html = truncatewords_html(post.body_html, turncate) else: turncate = False return {"post": post, "turncate": turncate}
def test_wordcount(self): self.assertEqual(wordcount(''), 0) self.assertEqual(wordcount('oneword'), 1) self.assertEqual(wordcount('lots of words'), 3) self.assertEqual(wordwrap('this is a long paragraph of text that ' 'really needs to be wrapped I\'m afraid', 14), "this is a long\nparagraph of\ntext that\nreally needs\nto be " "wrapped\nI'm afraid") self.assertEqual(wordwrap('this is a short paragraph of text.\n ' 'But this line should be indented', 14), 'this is a\nshort\nparagraph of\ntext.\n But this\nline ' 'should be\nindented') self.assertEqual(wordwrap('this is a short paragraph of text.\n ' 'But this line should be indented', 15), 'this is a short\n' 'paragraph of\ntext.\n But this line\nshould be\nindented')
def devotional_word_count(request): devotionals = Devotional.objects.all() count = 0 for d in devotionals: body = strip_tags(d.body) count += int(wordcount(d.body)) return render(request, 'devotionals/devotional_word_count.html', {'count': count})
def render(self, context): text = self.text.resolve(context) text = defaultfilters.urlize(text) random_id = random.randint(0,1000000000) value = '<div id="description_%s"><div class="info_less"><p>%s ' % (random_id, defaultfilters.truncatewords_html(text, 25),) if defaultfilters.wordcount(text) > 25: value += ' <a id="link_more_%s" class="bold small link_more" href="">%s</a>' % (random_id, _("show more"),) value += '</p></div>' value += '<div class="info_more" style="display:none;">%s <p><a id="link_less_%s" class="bold small link_less" href="">%s</a></p></div></div>' % (defaultfilters.linebreaks(text), random_id,_("show less")) return value
def test_non_string_input(self): self.assertEqual(wordcount(123), 1)
def test_count_multiple(self): self.assertEqual(wordcount("lots of words"), 3)
def test_count_one(self): self.assertEqual(wordcount("oneword"), 1)
def test_empty_string(self): self.assertEqual(wordcount(""), 0)
def description_wordcount(self): return wordcount(self.description)
def update_chapter_word_count(sender, instance, **kw): from django.template import defaultfilters as filters instance.words = filters.wordcount(filters.striptags(instance.text))
def reading_time(object): return wordcount(object)/250
def total_words(self): words = wordcount(self.body) return words
def test_wordcount(self): self.assertEqual(wordcount(''), 0) self.assertEqual(wordcount('oneword'), 1) self.assertEqual(wordcount('lots of words'), 3)
def message_wordcount(self): return wordcount(self.message)
def needs_trunc(value, max_words): if BLOG['truncater'] in value: return True if wordcount(value) > max_words : return True return False