Added Markdown rendering for `media_entry`
authorJoar Wandborg <git@wandborg.com>
Sun, 12 Jun 2011 01:24:31 +0000 (03:24 +0200)
committerJoar Wandborg <git@wandborg.com>
Sun, 12 Jun 2011 01:24:31 +0000 (03:24 +0200)
mediagoblin/db/models.py
mediagoblin/edit/views.py
mediagoblin/submit/views.py
mediagoblin/templates/mediagoblin/user_pages/media.html
mediagoblin/user_pages/views.py
mediagoblin/util.py
setup.py

index 3da97a4911bf641cfd67331a75886f51cd565c99..0b092d606cfa63dd8a47373f2859575006fffbb7 100644 (file)
@@ -73,7 +73,8 @@ class MediaEntry(Document):
         'title': unicode,
         'slug': unicode,
         'created': datetime.datetime,
-        'description': unicode,
+        'description': unicode, # May contain markdown/up
+        'description_html': unicode, # May contain plaintext, or HTML
         'media_type': unicode,
         'media_data': dict, # extra data relevant to this media_type
         'plugin_data': dict, # plugins can dump stuff here.
index c5f0f435b1ebd281d1ba1a3a19711cf08d102fcf..2bc53a54ad4194d038368dc94c1fe77f3a7aef13 100644 (file)
@@ -47,7 +47,14 @@ def edit_media(request, media):
                 u'An entry with that slug already exists for this user.')
         else:
             media['title'] = request.POST['title']
-            media['description'] = request.POST['description']
+            media['description'] = request.POST.get('description')
+            
+            import markdown
+            md = markdown.Markdown(
+                safe_mode = 'escape')
+            media['description_html'] = md.convert(
+                media['description'])
+
             media['slug'] = request.POST['slug']
             media.save()
 
index e9b5c37e0c4b4af2168141e7430eeaee114309b2..21562e6f4235a4928929c5cf267f984eeeb1e928 100644 (file)
@@ -48,6 +48,13 @@ def submit_start(request):
             entry = request.db.MediaEntry()
             entry['title'] = request.POST['title'] or unicode(splitext(filename)[0])
             entry['description'] = request.POST.get('description')
+            
+            import markdown
+            md = markdown.Markdown(
+                safe_mode = 'escape')
+            entry['description_html'] = md.convert(
+                entry['description'])
+            
             entry['media_type'] = u'image' # heh
             entry['uploader'] = request.user['_id']
 
index 200f13cdda64a2de7cf590c3e85d4cc6a2081325..44bc38b86842136d8427ff1228f2b90008fe1e3d 100644 (file)
@@ -25,7 +25,9 @@
     </h1>
     <img class="media_image" src="{{ request.app.public_store.file_url(
                   media.media_files.main) }}" />
-    <p>{{ media.description }}</p>
+    {% autoescape False %}
+    <p>{{ media.description_html }}</p>
+    {% endautoescape %}
     <p>Uploaded on
     {{ "%4d-%02d-%02d"|format(media.created.year,
                               media.created.month, media.created.day) }}
index 323c3e548dab3ed17fef16cb18a56db985235485..4ec0f0aac7ab864ef08b9f44f8e87e936831880f 100644 (file)
@@ -81,10 +81,10 @@ def atom_feed(request):
     feed = AtomFeed(request.matchdict['user'],
                feed_url=request.url,
                url=request.host_url)
-            
+    
     for entry in cursor:
         feed.add(entry.get('title'),
-            entry.get('description'),
+            entry.get('description_html'),
             content_type='html',
             author=request.matchdict['user'],
             updated=entry.get('created'),
index 64e21ca99e982c2d949bd0f7a8ab3b8e59ebfabe..1e8fa095a0a7890ac47e044ca9c05cb9af569a20 100644 (file)
@@ -34,7 +34,6 @@ from webob import Response, exc
 from mediagoblin import globals as mgoblin_globals
 from mediagoblin.db.util import ObjectId
 
-
 TESTS_ENABLED = False
 def _activate_testing():
     """
@@ -99,7 +98,7 @@ def get_jinja_env(template_loader, locale):
 
     template_env = jinja2.Environment(
         loader=template_loader, autoescape=True,
-        extensions=['jinja2.ext.i18n'])
+        extensions=['jinja2.ext.i18n', 'jinja2.ext.autoescape'])
 
     template_env.install_gettext_callables(
         mgoblin_globals.translations.gettext,
index 46da7276b2e177cfa6666bfaf0eed2030f880628..fb86d6008a6512b03220bfab9336f32079b38a26 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -42,6 +42,7 @@ setup(
         'translitcodec',
         'argparse',
         'webtest',
+        'Markdown',
         ],
     test_suite='nose.collector',