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): #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, arg): data = web.input() pid = arg path = data.path # 判断user的身份,是不是作者 if postModel.getPostByPostId(pid).postAuthor == user.id: postModel.post_update(pid, postImage=path) success = "s" return success
def POST(self): data = web.input() id = data.post_id uid = user.id p = postModel.getPostByPostId(id) magnitude = int(p.magnitude) ts = p.creation_ts delta = (datetime.datetime.now() - ts).days postModel.post_update(id, magnitude=magnitude - 1) score = magnitude / (delta + 2)**2.1 postModel.post_update(id, score=score) #更新最终的票数 postModel.delVoteUser(id, uid) #删除片段ID和投票的用户ID/时间 return '{"status": "y", "info": "已取消投票"}'
def POST(self): data = web.input() id = data.post_id uid = user.id p = postModel.getPostByPostId(id) magnitude = int(p.magnitude) ts = p.creation_ts delta = (datetime.datetime.now() - ts).days postModel.post_update(id, magnitude = magnitude - 1) score = magnitude / (delta + 2)**2.1 postModel.post_update(id, score = score) #更新最终的票数 postModel.delVoteUser(id, uid) #删除片段ID和投票的用户ID/时间 return '{"status": "y", "info": "已取消投票"}'
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 GET(self, arg, ntf_type=''): #ntf_type为提醒类型,用来让用户从提醒页面访问片段页面时可以看到对应提醒 post = postModel.getPostByPostId(arg) if post: post_author_info = users.get_user_by_id(post.postAuthor) node = nodeModel.getNodeByNodeId(post.nodeId) timestrf = misc.timestrf likers = postModel.get_voters_by_pid(post.id) likers_list = [] for i in xrange(len(likers)): likers_list += users.get_users_by_id(likers[i].uid) comments = postModel.get_comments_by_pid(post.id).list() commenters = [] for i in xrange(len(comments)): commenters += users.get_users_by_id(comments[i].uid) #是否登录, if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #是否投过票 is_voted = postModel.is_voted(arg, user.id) #得到提醒 notification_results, notification_num = notification.get_unread_notification( user.id) #得到@提醒 notification_mention_results, mention_num = notification.get_unread_metion_notifition( user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) #获取提醒页面传过来的提醒类型参数 ntf_type = web.input(ntf_type='').ntf_type ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num + mention_num else: rights = 0 is_voted = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None return view.base( view.post_single(rights, node, post, post_author_info, user, timestrf, likers_list, comments, commenters, ntf_type, is_voted, misc), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users) else: raise web.notfound()
def GET(self, arg, ntf_type=''): #ntf_type为提醒类型,用来让用户从提醒页面访问片段页面时可以看到对应提醒 post = postModel.getPostByPostId(arg) if post: post_author_info = users.get_user_by_id(post.postAuthor) node = nodeModel.getNodeByNodeId(post.nodeId) timestrf = misc.timestrf likers = postModel.get_voters_by_pid(post.id) likers_list = [] for i in xrange(len(likers)): likers_list += users.get_users_by_id(likers[i].uid) comments = postModel.get_comments_by_pid(post.id).list() commenters = [] for i in xrange(len(comments)): commenters += users.get_users_by_id(comments[i].uid) #是否登录, if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #是否投过票 is_voted = postModel.is_voted(arg, user.id) #得到提醒 notification_results, notification_num = notification.get_unread_notification(user.id) #得到@提醒 notification_mention_results, mention_num= notification.get_unread_metion_notifition(user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) #获取提醒页面传过来的提醒类型参数 ntf_type = web.input(ntf_type='').ntf_type ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num+mention_num else: rights = 0 is_voted = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None return view.base(view.post_single(rights, node, post, post_author_info, user, timestrf, likers_list, comments, commenters, ntf_type, is_voted, misc), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users) else: raise web.notfound()