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`
This commit is contained in:
Joar Wandborg 2011-06-29 01:29:39 +02:00
parent aa7d1a2fb6
commit 9074ee7c1d

View File

@ -15,13 +15,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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()