Пример #1
0
 def test_adds_nsfw_class(self):
     self.assertEqual(
         make_nsfw_safe(self.nsfw_text),
         '<div>FooBar</div><div><img class="nsfw" src="localhost"/></div><div>#nsfw</div>'
     )
     self.assertEqual(
         make_nsfw_safe(self.nsfw_text_with_classes),
         '<div>FooBar</div><div><img class="foobar nsfw" src="localhost"/></div><div>#nsfw</div>'
     )
     self.assertEqual(
         make_nsfw_safe(self.nsfw_text_empty_class),
         '<div>FooBar</div><div><img class="nsfw" src="localhost"/></div><div>#nsfw</div>'
     )
     self.assertEqual(
         make_nsfw_safe(self.nsfw_text_many_classes),
         '<div>FooBar</div><div><img class="foo bar nsfw" src="localhost"/></div><div>#nsfw</div>'
     )
Пример #2
0
 def test_adds_nsfw_class(self):
     self.assertEqual(
         make_nsfw_safe(self.nsfw_text),
         '<div>FooBar</div><div><img class="nsfw" src="localhost"/></div><div>#nsfw</div>'
     )
     self.assertEqual(
         make_nsfw_safe(self.nsfw_text_with_classes),
         '<div>FooBar</div><div><img class="foobar nsfw" src="localhost"/></div><div>#nsfw</div>'
     )
     self.assertEqual(
         make_nsfw_safe(self.nsfw_text_empty_class),
         '<div>FooBar</div><div><img class=" nsfw" src="localhost"/></div><div>#nsfw</div>'
     )
     self.assertEqual(
         make_nsfw_safe(self.nsfw_text_many_classes),
         '<div>FooBar</div><div><img class="foo bar nsfw" src="localhost"/></div><div>#nsfw</div>'
     )
Пример #3
0
 def render(self):
     rendered = commonmark(self.text).strip()
     if self.is_nsfw:
         rendered = make_nsfw_safe(rendered)
     if self.oembed:
         rendered = "%s<br>%s" % (rendered, self.oembed.oembed)
     if self.opengraph:
         rendered = "%s%s" % (rendered,
                              render_to_string(
                                  "content/_og_preview.html",
                                  {"opengraph": self.opengraph}))
     return rendered
Пример #4
0
 def render(self):
     """Pre-render text to Content.rendered."""
     text = self.get_and_linkify_tags()
     rendered = commonmark(text).strip()
     if self.is_nsfw:
         rendered = make_nsfw_safe(rendered)
     if self.oembed:
         rendered = "%s<br>%s" % (rendered, self.oembed.oembed)
     if self.opengraph:
         rendered = "%s%s" % (rendered,
                              render_to_string(
                                  "content/_og_preview.html",
                                  {"opengraph": self.opengraph}))
     self.rendered = rendered
     Content.objects.filter(id=self.id).update(rendered=rendered)
Пример #5
0
 def render(self):
     """Pre-render text to Content.rendered."""
     text = self.get_and_linkify_tags()
     rendered = commonmark(text).strip()
     rendered = process_text_links(rendered)
     if self.is_nsfw:
         rendered = make_nsfw_safe(rendered)
     if self.show_preview:
         if self.oembed:
             rendered = "%s<br>%s" % (
                 rendered, self.oembed.oembed
             )
         if self.opengraph:
             rendered = "%s%s" % (
                 rendered,
                 render_to_string("content/_og_preview.html", {"opengraph": self.opengraph})
             )
     self.rendered = rendered
     Content.objects.filter(id=self.id).update(rendered=rendered)