def POST(self, arg): data = web.input() postImage = data.post_Img postTitle = data.post_Name postCaption = data.post_Caption postArticle = data.post_Article postAuthor = user.id postTemp = data.temp nodeId = data.nodeID #入库 postModel.newPost(postImage, postTitle, postCaption, postArticle, postAuthor, postTemp, nodeId) #得到最新创建的post thisPost = postModel.getThisPostByUserId(postAuthor) node = nodeModel.getNodeByNodeId(nodeId) nodeAuthor = users.get_user_by_id(node.node_author) #判断是不是在自己创建的话题中发布片段 if nodeAuthor.id != int(postAuthor): #如果开启了邮件提醒,给此片段所属话题的作者发送邮件 person = users.get_profile_by_user_id(node.node_author) if person.has_key('email_subscribe') and person.email_subscribe == 1 and nodeAuthor.email: email_templates.someone_creat_new_post(user, nodeAuthor, node, thisPost) print '=== email send ==' #插入提醒 notification.new_notification(node.node_author, user.id, thisPost.id, nodeId, tp=4) return '{"post_id":'+ str(thisPost.id)+ ',"status":"y"}'
def POST(self): #note 需要判断数据库中用户是不是已经投过票了。 data = web.input() id = data.post_id uid = user.id #当前用户id p = postModel.getPostByPostId(id) #得到目标post magnitude = int(p.magnitude) #得到post的实际投票数 ts = p.creation_ts #得到post的创建时间 delta = (datetime.datetime.now() - ts).days #得到创建时间距今多少天 postModel.post_update(id, magnitude = magnitude + 1) #给post的实际投票数+1, 保存最终得票数 score = magnitude / (delta + 2)**2.1 #算出最终得票数 postModel.post_update(id, score = score) #入库 postModel.addVoteUser(id, uid) #记录片段ID和投票的用户ID/时间 #插入提醒 判断是不是自己喜欢自己的 if p.postAuthor != int(uid): notification.new_notification(p.postAuthor, uid, id, p.nodeId, tp=2) #如果开启了邮件提醒,给作者发送邮件 author = users.get_user_by_id(p.postAuthor) person = users.get_profile_by_user_id(p.postAuthor) if person.has_key('email_subscribe') and person.email_subscribe == 1 and author.email: email_templates.someone_like_ur_post(user, author, p) print '=== email send ==' return '{"status": "y", "info": "投票成功"}'
def POST(self, pid): data = web.input() uid = user.id aid = data.aid #note : 需要改成在后端通过pid得到aid,不能从前端传过来 p = postModel.getPostByPostId(pid) #得到目标post reg_regchar = '@([a-zA-Z0-9][\w\-\.\_]+)' comment = data.postComment comment = htmlquote(comment).strip().replace("\r\n", "<br/>") usernames = re.findall(reg_regchar, comment) nicknames = [] nickname_list = [] mid_list = [] # @提醒 for i in xrange(len(usernames)): if not users.is_username_available(usernames[i]): nicknames += users.get_user_by_username(usernames[i]).nickname.replace(' ', ' ').split() comment = comment.replace('@'+ usernames[i], '@<a href="/member/'+ usernames[i] +'">' + nicknames[i] + '</a>') #得到@的用户id 以|分割组成字符串 mid_list += str(users.get_user_by_username(usernames[i]).id).split() #去重 mid_list = sorted(set(mid_list),key=mid_list.index) #以字符串形势保存@到的uid,以|分割 # mention_id_list = '|'.join(mid_list) else: nicknames += usernames[i].split() comment = comment.replace('@'+ usernames[i], '@' + nicknames[i]) # @提醒 for mid in mid_list: if int(mid) != int(aid): notification.new_mention_notification(pid, p.nodeId, aid, uid,mid) print '=======notification send=====' # 评论提醒 tp=1 表示是评论类型的提醒 同时判断是不是本人评论本人 #这里很奇怪,不能直接判断aid 和 uid 是否相等,必须转成int if int(aid) != int(uid): notification.new_notification(aid, uid, pid, p.nodeId, 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) +'"}'
def POST(self, arg): data = web.input() postImage = data.post_Img postTitle = data.post_Name postCaption = data.post_Caption postArticle = data.post_Article postAuthor = user.id postTemp = data.temp nodeId = data.nodeID #入库 postModel.newPost(postImage, postTitle, postCaption, postArticle, postAuthor, postTemp, nodeId) #得到最新创建的post thisPost = postModel.getThisPostByUserId(postAuthor) node = nodeModel.getNodeByNodeId(nodeId) nodeAuthor = users.get_user_by_id(node.node_author) #判断是不是在自己创建的话题中发布片段 if nodeAuthor.id != int(postAuthor): #如果开启了邮件提醒,给此片段所属话题的作者发送邮件 person = users.get_profile_by_user_id(node.node_author) if person.has_key( 'email_subscribe' ) and person.email_subscribe == 1 and nodeAuthor.email: email_templates.someone_creat_new_post(user, nodeAuthor, node, thisPost) print '=== email send ==' #插入提醒 notification.new_notification(node.node_author, user.id, thisPost.id, nodeId, tp=4) return '{"post_id":' + str(thisPost.id) + ',"status":"y"}'
def POST(self): #note 需要判断数据库中用户是不是已经投过票了。 data = web.input() id = data.post_id uid = user.id #当前用户id p = postModel.getPostByPostId(id) #得到目标post magnitude = int(p.magnitude) #得到post的实际投票数 ts = p.creation_ts #得到post的创建时间 delta = (datetime.datetime.now() - ts).days #得到创建时间距今多少天 postModel.post_update(id, magnitude=magnitude + 1) #给post的实际投票数+1, 保存最终得票数 score = magnitude / (delta + 2)**2.1 #算出最终得票数 postModel.post_update(id, score=score) #入库 postModel.addVoteUser(id, uid) #记录片段ID和投票的用户ID/时间 #插入提醒 判断是不是自己喜欢自己的 if p.postAuthor != int(uid): notification.new_notification(p.postAuthor, uid, id, p.nodeId, tp=2) #如果开启了邮件提醒,给作者发送邮件 author = users.get_user_by_id(p.postAuthor) person = users.get_profile_by_user_id(p.postAuthor) if person.has_key( 'email_subscribe' ) and person.email_subscribe == 1 and author.email: email_templates.someone_like_ur_post(user, author, p) print '=== email send ==' return '{"status": "y", "info": "投票成功"}'
def POST(self, pid): data = web.input() uid = user.id aid = data.aid #note : 需要改成在后端通过pid得到aid,不能从前端传过来 p = postModel.getPostByPostId(pid) #得到目标post reg_regchar = '@([a-zA-Z0-9][\w\-\.\_]+)' comment = data.postComment comment = htmlquote(comment).strip().replace("\r\n", "<br/>") usernames = re.findall(reg_regchar, comment) nicknames = [] nickname_list = [] mid_list = [] # @提醒 for i in xrange(len(usernames)): if not users.is_username_available(usernames[i]): nicknames += users.get_user_by_username( usernames[i]).nickname.replace(' ', ' ').split() comment = comment.replace( '@' + usernames[i], '@<a href="/member/' + usernames[i] + '">' + nicknames[i] + '</a>') #得到@的用户id 以|分割组成字符串 mid_list += str(users.get_user_by_username( usernames[i]).id).split() #去重 mid_list = sorted(set(mid_list), key=mid_list.index) #以字符串形势保存@到的uid,以|分割 # mention_id_list = '|'.join(mid_list) else: nicknames += usernames[i].split() comment = comment.replace('@' + usernames[i], '@' + nicknames[i]) # @提醒 for mid in mid_list: if int(mid) != int(aid): notification.new_mention_notification(pid, p.nodeId, aid, uid, mid) print '=======notification send=====' # 评论提醒 tp=1 表示是评论类型的提醒 同时判断是不是本人评论本人 #这里很奇怪,不能直接判断aid 和 uid 是否相等,必须转成int if int(aid) != int(uid): notification.new_notification(aid, uid, pid, p.nodeId, 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) + '"}'