Beispiel #1
0
def render_content(comment, number=None):
    try:
        number = int(number)
    except (ValueError, TypeError):
        number = get_wrapped_words_number()

    # Restrict 2 or more line breaks to 2 <br>
    content = MULTIPLE_NEW_LINE_RE.sub(r'\1<br><br>\3', comment.content)
    content = SINGLE_NEW_LINE_RE.sub(r'\1<br>\3', content)
    content_words = content.split()
    if not number or len(content_words) <= number:
        text_1 = content
        text_2 = None
    else:
        text_1 = ' '.join(content_words[:number])
        text_2 = ' '.join(content_words[number:])

    return {'text_1': text_1, 'text_2': text_2, 'urlhash': comment.urlhash}
Beispiel #2
0
def render_content(comment, number=None):
    try:
        number = int(number)
    except (ValueError, TypeError):
        number = get_wrapped_words_number()

    # this is necessary to avoid XSS attacks
    escaped_content = conditional_escape(comment.content)
    content = _restrict_line_breaks(escaped_content)
    content_words = content.split()
    if not number or len(content_words) <= number:
        text_1 = content
        text_2 = None
    else:
        text_1 = ' '.join(content_words[:number])
        text_2 = ' '.join(content_words[number:])

    return {
        'text_1': mark_safe(text_1),
        'text_2': mark_safe(text_2) if text_2 else None,
        'urlhash': comment.urlhash
    }
Beispiel #3
0
 def test_get_wrapped_words_number_fails_on_non_int_value(self):
     with self.assertRaises(ImproperlyConfigured) as e:
         get_wrapped_words_number()
     self.assertEqual(str(e.exception),
                      ErrorMessage.WRAP_CONTENT_WORDS_NOT_INT)
     self.assertTextTranslated(ErrorMessage.WRAP_CONTENT_WORDS_NOT_INT)
Beispiel #4
0
 def test_get_wrapped_words_number_return_0_for_None(self):
     self.assertEqual(get_wrapped_words_number(), 0)
Beispiel #5
0
 def test_get_wrapped_words_number_return_specified_setting_value(self):
     self.assertEqual(get_wrapped_words_number(), 20)
Beispiel #6
0
 def test_using_integer_value(self):
     self.assertEqual(get_wrapped_words_number(), 20)
Beispiel #7
0
 def test_using_None(self):
     self.assertEqual(get_wrapped_words_number(), 0)