Esempio n. 1
0
 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
Esempio n. 2
0
 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
Esempio n. 3
0
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
Esempio n. 4
0
 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')
Esempio n. 5
0
 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')
Esempio n. 6
0
File: models.py Progetto: Foxas/369
 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)
Esempio n. 7
0
File: models.py Progetto: Foxas/369
 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)
Esempio n. 8
0
File: post.py Progetto: Apkawa/blog
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}
Esempio n. 9
0
    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')
Esempio n. 10
0
    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')
Esempio n. 11
0
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})
Esempio n. 12
0
    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
Esempio n. 13
0
 def test_non_string_input(self):
     self.assertEqual(wordcount(123), 1)
Esempio n. 14
0
 def test_count_multiple(self):
     self.assertEqual(wordcount("lots of words"), 3)
Esempio n. 15
0
 def test_count_one(self):
     self.assertEqual(wordcount("oneword"), 1)
Esempio n. 16
0
 def test_empty_string(self):
     self.assertEqual(wordcount(""), 0)
Esempio n. 17
0
 def description_wordcount(self):
     return wordcount(self.description)
Esempio n. 18
0
def update_chapter_word_count(sender, instance, **kw):
    from django.template import defaultfilters as filters
    instance.words = filters.wordcount(filters.striptags(instance.text))
Esempio n. 19
0
def reading_time(object):
	return wordcount(object)/250
Esempio n. 20
0
 def total_words(self):
     words = wordcount(self.body)
     return words
Esempio n. 21
0
 def test_wordcount(self):
     self.assertEqual(wordcount(''), 0)
     self.assertEqual(wordcount('oneword'), 1)
     self.assertEqual(wordcount('lots of words'), 3)
Esempio n. 22
0
 def test_count_multiple(self):
     self.assertEqual(wordcount("lots of words"), 3)
Esempio n. 23
0
 def test_wordcount(self):
     self.assertEqual(wordcount(''), 0)
     self.assertEqual(wordcount('oneword'), 1)
     self.assertEqual(wordcount('lots of words'), 3)
Esempio n. 24
0
 def test_non_string_input(self):
     self.assertEqual(wordcount(123), 1)
Esempio n. 25
0
 def message_wordcount(self):
     return wordcount(self.message)
Esempio n. 26
0
 def test_empty_string(self):
     self.assertEqual(wordcount(""), 0)
Esempio n. 27
0
 def test_count_one(self):
     self.assertEqual(wordcount("oneword"), 1)
Esempio n. 28
0
def needs_trunc(value, max_words):
  if BLOG['truncater'] in value:
    return True
  if wordcount(value) > max_words :
    return True
  return False