Last active
December 12, 2015 01:18
-
-
Save naoyeye/4689495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#添加评论 | |
class new_post_comment: | |
@session.login_required | |
def POST(self, pid): | |
data = web.input() | |
reg_regchar = '@([a-zA-Z0-9][\w\-\.\_]+)' #正则匹配username | |
comment = data.postComment | |
comment = htmlquote(comment).strip().replace("\r\n", "<br/>") #内容过滤 | |
usernames = re.findall(reg_regchar, comment) #得到username数组 | |
nicknames = [] | |
for i in xrange(len(usernames)): | |
#得到nickname列表 | |
nicknames += users.get_user_by_username(usernames[i]).nickname.replace(' ', ' ').split() | |
for i in xrange(len(usernames)): | |
#替换评论中的username为nickname | |
comment = comment.replace(usernames[i], '<a href="/member/'+ usernames[i] +'">' + nicknames[i] + '</a>') | |
print comment | |
aid = data.aid #note : 需要改成在后端通过pid得到aid,不能从前端传过来 | |
uid = user.id | |
#插入提醒 tp=1 表示是评论类型的提醒 同时判断是不是本人评论本人 | |
#这里很奇怪,不能直接判断aid 和 uid 是否相等,必须转成int | |
if int(aid) != int(uid): | |
notification.new_notification(aid, uid, pid, tp=1) | |
#如果开启了邮件提醒,给作者发送邮件 | |
author = users.get_user_by_id(aid) | |
person = users.get_profile_by_user_id(aid) | |
p = postModel.getPostByPostId(pid) #得到目标post | |
if person.has_key('email_subscribe') and person.email_subscribe == 1 and author.email: | |
email_templates.someone_comment_ur_post(user, author, p) | |
print '=== email send ==' | |
postModel.add_post_comment(comment, uid, pid) | |
#得到刚刚添加的comment的id,返回ajax给li添加id 供删除用 | |
last_comment = postModel.get_just_added_comment(uid, pid).id | |
return '{"status": "y", "comment_id": "'+ str(last_comment) +'"}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment