Feature #400 - Resize images to fit on page - Additions
[mediagoblin.git] / mediagoblin / util.py
index 0e43a1f5477f14d8921531fb9f4770ccd65d7c2f..a542566356d4bcc580fd7fb95a4fa2b26eb7ef3c 100644 (file)
@@ -32,8 +32,11 @@ from lxml.html.clean import Cleaner
 import markdown
 
 from mediagoblin import mg_globals
+from mediagoblin import messages
 from mediagoblin.db.util import ObjectId
 
+DISPLAY_IMAGE_FETCHING_ORDER = [u'medium', u'original', u'thumb']
+
 TESTS_ENABLED = False
 def _activate_testing():
     """
@@ -104,6 +107,10 @@ def get_jinja_env(template_loader, locale):
         mg_globals.translations.gettext,
         mg_globals.translations.ngettext)
 
+    # All templates will know how to ...
+    # ... fetch all waiting messages and remove them from the queue
+    template_env.globals['fetch_messages'] = messages.fetch_messages
+
     if exists(locale):
         SETUP_JINJA_ENVS[locale] = template_env
 
@@ -373,6 +380,10 @@ HTML_CLEANER = Cleaner(
 
 
 def clean_html(html):
+    # clean_html barfs on an empty string
+    if not html:
+        return u''
+
     return HTML_CLEANER.clean_html(html)
 
 
@@ -383,6 +394,11 @@ def cleaned_markdown_conversion(text):
     """
     Take a block of text, run it through MarkDown, and clean its HTML.
     """
+    # Markdown will do nothing with and clean_html can do nothing with
+    # an empty string :)
+    if not text:
+        return u''
+
     return clean_html(MARKDOWN_INSTANCE.convert(text))