def media_post_comment(request, media): """ recieves POST from a MediaEntry() comment form, saves the comment. """ if not request.method == 'POST': raise MethodNotAllowed() comment = request.db.TextComment() comment.actor = request.user.id comment.content = six.text_type(request.form['comment_content']) # Show error message if commenting is disabled. if not mg_globals.app_config['allow_comments']: messages.add_message(request, messages.ERROR, _("Sorry, comments are disabled.")) elif not comment.content.strip(): messages.add_message(request, messages.ERROR, _("Oops, your comment was empty.")) else: create_activity("post", comment, comment.actor, target=media) add_comment_subscription(request.user, media) comment.save() link = request.db.Comment() link.target = media link.comment = comment link.save() messages.add_message(request, messages.SUCCESS, _('Your comment has been posted!')) trigger_notification(link, media, request) return redirect_obj(request, media)
def media_post_comment(request, media): """ recieves POST from a MediaEntry() comment form, saves the comment. """ if not request.method == 'POST': raise MethodNotAllowed() comment = request.db.MediaComment() comment.media_entry = media.id comment.author = request.user.id comment.content = unicode(request.form['comment_content']) # Show error message if commenting is disabled. if not mg_globals.app_config['allow_comments']: messages.add_message( request, messages.ERROR, _("Sorry, comments are disabled.")) elif not comment.content.strip(): messages.add_message( request, messages.ERROR, _("Oops, your comment was empty.")) else: comment.save() messages.add_message( request, messages.SUCCESS, _('Your comment has been posted!')) trigger_notification(comment, media, request) add_comment_subscription(request.user, media) return redirect_obj(request, media)