From 44e2da2fe60a3b8765d0fef5a9ce0c3e5997dd01 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sun, 12 Jun 2011 03:24:31 +0200 Subject: [PATCH] Added Markdown rendering for `media_entry` --- mediagoblin/db/models.py | 3 ++- mediagoblin/edit/views.py | 9 ++++++++- mediagoblin/submit/views.py | 7 +++++++ mediagoblin/templates/mediagoblin/user_pages/media.html | 4 +++- mediagoblin/user_pages/views.py | 4 ++-- mediagoblin/util.py | 3 +-- setup.py | 1 + 7 files changed, 24 insertions(+), 7 deletions(-) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 3da97a49..0b092d60 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -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. diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index c5f0f435..2bc53a54 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -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() diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index e9b5c37e..21562e6f 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -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'] diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 200f13cd..44bc38b8 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -25,7 +25,9 @@ -

{{ media.description }}

+ {% autoescape False %} +

{{ media.description_html }}

+ {% endautoescape %}

Uploaded on {{ "%4d-%02d-%02d"|format(media.created.year, media.created.month, media.created.day) }} diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 323c3e54..4ec0f0aa 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -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'), diff --git a/mediagoblin/util.py b/mediagoblin/util.py index 64e21ca9..1e8fa095 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -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, diff --git a/setup.py b/setup.py index 46da7276..fb86d600 100644 --- a/setup.py +++ b/setup.py @@ -42,6 +42,7 @@ setup( 'translitcodec', 'argparse', 'webtest', + 'Markdown', ], test_suite='nose.collector', -- 2.25.1