Пример #1
0
    def test_tagcloser(self):
        """
        Test tags are closed, and tags that shouldn't be closed aren't.
        """
        self.assertEqual(TagCloser("<p>Unclosed paragraph").html,
                         "<p>Unclosed paragraph</p>")

        self.assertEqual(TagCloser("Line break<br>").html,
                         "Line break<br>")
Пример #2
0
 def description_from_content(self):
     """
     Returns the first block or sentence of the first content-like
     field.
     """
     description = ""
     # Use the first RichTextField, or TextField if none found.
     for field_type in (RichTextField, models.TextField):
         if not description:
             for field in self._meta.fields:
                 if isinstance(field, field_type) and \
                     field.name != "description":
                     description = getattr(self, field.name)
                     if description:
                         from mezzanine.core.templatetags.mezzanine_tags \
                         import richtext_filters
                         description = richtext_filters(description)
                         break
     # Fall back to the title if description couldn't be determined.
     if not description:
         description = str(self)
     # Strip everything after the first block or sentence.
     ends = ("</p>", "<br />", "<br/>", "<br>", "</ul>", "\n", ". ", "! ",
             "? ")
     for end in ends:
         pos = description.lower().find(end)
         if pos > -1:
             description = TagCloser(description[:pos]).html
             break
     else:
         description = truncatewords_html(description, 100)
     return description