# 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()"""
@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
updated=entry.get('created'),
url=entry.url_for_self(request.urlgen))
- return feed.get_response()
+ return feed.get_response()