本文整理汇总了Python中apps.social.models.MActivity.new_comment_reply方法的典型用法代码示例。如果您正苦于以下问题:Python MActivity.new_comment_reply方法的具体用法?Python MActivity.new_comment_reply怎么用?Python MActivity.new_comment_reply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apps.social.models.MActivity
的用法示例。
在下文中一共展示了MActivity.new_comment_reply方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_comment_reply
# 需要导入模块: from apps.social.models import MActivity [as 别名]
# 或者: from apps.social.models.MActivity import new_comment_reply [as 别名]
def save_comment_reply(request):
code = 1
feed_id = int(request.POST['story_feed_id'])
story_id = request.POST['story_id']
comment_user_id = request.POST['comment_user_id']
reply_comments = request.POST.get('reply_comments')
reply_id = request.POST.get('reply_id')
format = request.REQUEST.get('format', 'json')
original_message = None
if not reply_comments:
return json.json_response(request, {'code': -1, 'message': 'Reply comments cannot be empty.'})
shared_story = MSharedStory.objects.get(user_id=comment_user_id,
story_feed_id=feed_id,
story_guid=story_id)
reply = MCommentReply()
reply.user_id = request.user.pk
reply.publish_date = datetime.datetime.now()
reply.comments = reply_comments
if reply_id:
replies = []
for story_reply in shared_story.replies:
if (story_reply.user_id == reply.user_id and
story_reply.reply_id == ObjectId(reply_id)):
reply.publish_date = story_reply.publish_date
reply.reply_id = story_reply.reply_id
original_message = story_reply.comments
replies.append(reply)
else:
replies.append(story_reply)
shared_story.replies = replies
logging.user(request, "~FCUpdating comment reply in ~FM%s: ~SB~FB%s~FM" % (
shared_story.story_title[:20], reply_comments[:30]))
else:
reply.reply_id = ObjectId()
logging.user(request, "~FCReplying to comment in: ~FM%s: ~SB~FB%s~FM" % (
shared_story.story_title[:20], reply_comments[:30]))
shared_story.replies.append(reply)
shared_story.save()
comment, profiles = shared_story.comment_with_author_and_profiles()
# Interaction for every other replier and original commenter
MActivity.new_comment_reply(user_id=request.user.pk,
comment_user_id=comment['user_id'],
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title)
if comment['user_id'] != request.user.pk:
MInteraction.new_comment_reply(user_id=comment['user_id'],
reply_user_id=request.user.pk,
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title)
reply_user_ids = list(r['user_id'] for r in comment['replies'])
for user_id in set(reply_user_ids).difference([comment['user_id']]):
if request.user.pk != user_id:
MInteraction.new_reply_reply(user_id=user_id,
comment_user_id=comment['user_id'],
reply_user_id=request.user.pk,
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title)
EmailCommentReplies.apply_async(kwargs=dict(shared_story_id=shared_story.id,
reply_id=reply.reply_id), countdown=60)
if format == 'html':
comment = MSharedStory.attach_users_to_comment(comment, profiles)
return render_to_response('social/story_comment.xhtml', {
'comment': comment,
}, context_instance=RequestContext(request))
else:
return json.json_response(request, {
'code': code,
'comment': comment,
'reply_id': reply.reply_id,
'user_profiles': profiles
})
示例2: save_comment_reply
# 需要导入模块: from apps.social.models import MActivity [as 别名]
# 或者: from apps.social.models.MActivity import new_comment_reply [as 别名]
def save_comment_reply(request):
code = 1
feed_id = int(request.POST["story_feed_id"])
story_id = request.POST["story_id"]
comment_user_id = request.POST["comment_user_id"]
reply_comments = request.POST.get("reply_comments")
reply_id = request.POST.get("reply_id")
format = request.REQUEST.get("format", "json")
original_message = None
if not reply_comments:
return json.json_response(request, {"code": -1, "message": "Reply comments cannot be empty."})
shared_story = MSharedStory.objects.get(user_id=comment_user_id, story_feed_id=feed_id, story_guid=story_id)
reply = MCommentReply()
reply.user_id = request.user.pk
reply.publish_date = datetime.datetime.now()
reply.comments = reply_comments
if reply_id:
replies = []
for story_reply in shared_story.replies:
if story_reply.user_id == reply.user_id and story_reply.reply_id == ObjectId(reply_id):
reply.publish_date = story_reply.publish_date
reply.reply_id = story_reply.reply_id
original_message = story_reply.comments
replies.append(reply)
else:
replies.append(story_reply)
shared_story.replies = replies
logging.user(
request,
"~FCUpdating comment reply in ~FM%s: ~SB~FB%s~FM" % (shared_story.story_title[:20], reply_comments[:30]),
)
else:
reply.reply_id = ObjectId()
logging.user(
request,
"~FCReplying to comment in: ~FM%s: ~SB~FB%s~FM" % (shared_story.story_title[:20], reply_comments[:30]),
)
shared_story.replies.append(reply)
shared_story.save()
comment, profiles = shared_story.comment_with_author_and_profiles()
# Interaction for every other replier and original commenter
MActivity.new_comment_reply(
user_id=request.user.pk,
comment_user_id=comment["user_id"],
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title,
)
if comment["user_id"] != request.user.pk:
MInteraction.new_comment_reply(
user_id=comment["user_id"],
reply_user_id=request.user.pk,
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title,
)
reply_user_ids = list(r["user_id"] for r in comment["replies"])
for user_id in set(reply_user_ids).difference([comment["user_id"]]):
if request.user.pk != user_id:
MInteraction.new_reply_reply(
user_id=user_id,
comment_user_id=comment["user_id"],
reply_user_id=request.user.pk,
reply_content=reply_comments,
original_message=original_message,
story_id=story_id,
story_feed_id=feed_id,
story_title=shared_story.story_title,
)
EmailCommentReplies.apply_async(kwargs=dict(shared_story_id=shared_story.id, reply_id=reply.reply_id), countdown=60)
if format == "html":
comment = MSharedStory.attach_users_to_comment(comment, profiles)
return render_to_response(
"social/story_comment.xhtml", {"comment": comment}, context_instance=RequestContext(request)
)
else:
return json.json_response(
request, {"code": code, "comment": comment, "reply_id": reply.reply_id, "user_profiles": profiles}
)