From 9074ee7c1df9cca8a250cc837c3e3efb8e359649 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Wed, 29 Jun 2011 01:29:39 +0200 Subject: [PATCH] Issue #362 - Updated `mediagoblin.user_pages.views` to handle new "Simple comments" feature * ADDED `media_post_comment(request)` which creates `MediaComments` from POST requests * UPDATED `media_home(request, media, **kwargs)` now passes `comments`, `pagination` and `comments_form` to `media.html` --- mediagoblin/user_pages/views.py | 51 ++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index d6cd6034..67a57d97 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -15,13 +15,18 @@ # along with this program. If not, see . from webob import exc -from mediagoblin.db.util import DESCENDING -from mediagoblin.util import Pagination, render_to_response +from mediagoblin.db.util import DESCENDING, ObjectId +from mediagoblin.util import Pagination, render_to_response, redirect, \ + clean_html +from mediagoblin.user_pages import forms as user_forms -from mediagoblin.decorators import uses_pagination, get_user_media_entry +from mediagoblin.decorators import uses_pagination, get_user_media_entry, \ + require_active_login from werkzeug.contrib.atom import AtomFeed +import markdown + @uses_pagination def user_home(request, page): """'Homepage' of a User()""" @@ -78,13 +83,45 @@ def user_gallery(request, page): @get_user_media_entry -def media_home(request, media): - """'Homepage' of a MediaEntry()""" +@uses_pagination +def media_home(request, media, **kwargs): + """ + 'Homepage' of a MediaEntry() + """ + + comment_form = user_forms.MediaCommentForm(request.POST) + + (comments, pagination) = media.get_comments(kwargs.get('page')) + return render_to_response( request, 'mediagoblin/user_pages/media.html', - {'media': media}) + {'media': media, + 'comments': comments, + 'pagination': pagination, + 'comment_form': comment_form}) + +@require_active_login +def media_post_comment(request): + """ + recieves POST from a MediaEntry() comment form, saves the comment. + """ + comment = request.db.MediaComment() + comment['media_entry'] = ObjectId(request.matchdict['media']) + comment['author'] = request.user['_id'] + comment['content'] = request.POST['comment'] + + md = markdown.Markdown( + safe_mode = 'escape') + comment['content_html'] = clean_html( + md.convert( + comment['content'])) + + comment.save() + return redirect(request, 'mediagoblin.user_pages.media_home', + media = request.matchdict['media'], + user = request.matchdict['user']) ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 5 @@ -117,4 +154,4 @@ def atom_feed(request): updated=entry.get('created'), url=entry.url_for_self(request.urlgen)) - return feed.get_response() + return feed.get_response() -- 2.25.1