diff options
author | Emily O'Leary <lotusecho@ThinkLotus> | 2013-03-24 21:42:42 -0400 |
---|---|---|
committer | Rodney Ewing <ewing.rj@gmail.com> | 2013-08-07 16:33:09 -0700 |
commit | 5ab60299619557307cf38aa14824c8576f23f21c (patch) | |
tree | 6d1d19ddbbfa1405105ca34393a8ea8770b396c4 /mediagoblin/user_pages/views.py | |
parent | 9da4e8049f2de900f7aa12f2fed8c60d6749ff0b (diff) | |
download | mediagoblin-5ab60299619557307cf38aa14824c8576f23f21c.tar.lz mediagoblin-5ab60299619557307cf38aa14824c8576f23f21c.tar.xz mediagoblin-5ab60299619557307cf38aa14824c8576f23f21c.zip |
Added comment preview functionality to user pages. It works by passing the comment's value as a JSON string to a new handler that lives at /ajax/comment/preview. The query string is decoded, unquoted, and has its leading and trailing quotes removed to match the input that cleaned_markdown_conversion expects.
It does this in real time with a 500ms lag by using a timer. Initially I tried the onChange handler but you need to lose focus for that to process. The javascript timer is only invoked if the add comment button is pressed. A request is only sent if the comment box is not empty and the current value is not the same as the last value.
Diffstat (limited to 'mediagoblin/user_pages/views.py')
-rw-r--r-- | mediagoblin/user_pages/views.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 596d4c20..2bc56fd5 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -16,19 +16,21 @@ import logging import datetime +import json +import urllib from mediagoblin import messages, mg_globals from mediagoblin.db.models import (MediaEntry, MediaTag, Collection, CollectionItem, User) from mediagoblin.tools.response import render_to_response, render_404, \ redirect, redirect_obj +from mediagoblin.tools.text import cleaned_markdown_conversion from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.pagination import Pagination from mediagoblin.user_pages import forms as user_forms from mediagoblin.user_pages.lib import add_media_to_collection from mediagoblin.notifications import trigger_notification, \ add_comment_subscription, mark_comment_notification_seen - from mediagoblin.decorators import (uses_pagination, get_user_media_entry, get_media_entry_by_id, require_active_login, user_may_delete_media, user_may_alter_collection, @@ -36,6 +38,7 @@ from mediagoblin.decorators import (uses_pagination, get_user_media_entry, from werkzeug.contrib.atom import AtomFeed from werkzeug.exceptions import MethodNotAllowed +from werkzeug.wrappers import Response _log = logging.getLogger(__name__) @@ -166,6 +169,7 @@ def media_post_comment(request, media): comment = request.db.MediaComment() comment.media_entry = media.id comment.author = request.user.id + print request.form['comment_content'] comment.content = unicode(request.form['comment_content']) # Show error message if commenting is disabled. @@ -193,6 +197,18 @@ def media_post_comment(request, media): return redirect_obj(request, media) + +def media_preview_comment(request): + + comment = unicode(urllib.unquote(request.query_string).decode('string_escape')) + if comment.startswith('"') and comment.endswith('"'): + comment = comment[1:-1] + print comment + #decoderRing = json.JSONDecoder() + #comment = decoderRing.decode(request.query_string) + + return Response(json.dumps(cleaned_markdown_conversion(comment))) + @get_media_entry_by_id @require_active_login def media_collect(request, media): |