Example #1
0
    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"}'
Example #2
0
    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": "投票成功"}'
Example #3
0
    def GET(self, username, p=1):
        u = users.get_user_by_username(username)
        profile = users.get_profile_by_user_id(u.id)

        page = int(p)
        perpage = 10
        offset = (page - 1) * perpage

        posts = postModel.groupGetCreatedPostsByUserId(u.id, offset, perpage).list()
        nodeids = []
        for i in xrange(len(posts)):
            nodeids += str(posts[i].nodeId).split()

        nodeList = []
        for i in xrange(len(nodeids)):
            nodeList += nodeModel.getNodesByNodeId(nodeids[i])

        authors = []
        for i in xrange(len(nodeList)):
            authors += users.get_users_by_id(nodeList[i].node_author)

        #是否登录,
        if user.is_logged:
            per = users.get_permission_by_douid(user.douban_id)
            rights = per[0].rights
            #得到提醒
            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_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.member_node_contributed(u, profile, nodeList, authors),user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
Example #4
0
    def GET(self, username, p=1):
        u = users.get_user_by_username(username)
        print user

        if u:
            page = int(p)
            perpage = 5
            offset = (page - 1) * perpage

            created_posts = postModel.getCreatedPostsByUserId(u.id, offset, perpage).list()

            nodes = []
            for i in xrange(len(created_posts)):
                nodes += nodeModel.getNodesByNodeId(created_posts[i].nodeId)

            #得到资料
            profile = users.get_profile_by_user_id(u.id)

            #是否登录,
            if user.is_logged:
                per = users.get_permission_by_douid(user.douban_id)
                rights = per[0].rights
                #得到提醒
                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_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.member_home(u, profile, created_posts, nodes, user), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
        else:
            raise web.notfound()
Example #5
0
    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(' ', '&nbsp;').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) +'"}'
Example #6
0
    def GET(self, username, p=1):
        u = users.get_user_by_username(username)
        profile = users.get_profile_by_user_id(u.id)

        page = int(p)
        perpage = 10
        offset = (page - 1) * perpage

        nodeList = nodeModel.getCreatedNodesByUserId(u.id, offset,
                                                     perpage).list()

        #是否登录,
        if user.is_logged:
            per = users.get_permission_by_douid(user.douban_id)
            rights = per[0].rights
            #得到提醒
            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_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.member_node(u, profile, nodeList,
                                          user), user, siteName, rights,
                         ntf_list, notification_num, ntf_posts, ntf_users)
Example #7
0
    def GET(self):
        # u = users.get_user_by_id(session.get_user_id())
        # ut = u.nicknameChangeTime #得到上次修改昵称的时间
        # c = datetime.datetime.now()#得到当前时间

        # if (c - ut).days < 30: #时间差
        #     can_change_nickname = False
        # else:
        #     can_change_nickname = True

        #得到权限
        per = users.get_permission_by_douid(user.douban_id)
        rights = per[0].rights

        #得到提醒
        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_list = ntf_list + mtf_list
        ntf_posts = ntf_posts + mtf_posts
        ntf_users = ntf_users + mtf_users
        notification_num = notification_num + mention_num

        #得到资料设置
        profile = users.get_profile_by_user_id(user.id)
        #得到邮箱验证状态
        confirm = users.get_confirm_email_by_douban_id(user.douban_id)

        return view.base(view.member_setting_profile(user, profile, confirm),
                         user, siteName, rights, ntf_list, notification_num,
                         ntf_posts, ntf_users)
Example #8
0
    def GET(self):
        # u = users.get_user_by_id(session.get_user_id())
        # ut = u.nicknameChangeTime #得到上次修改昵称的时间
        # c = datetime.datetime.now()#得到当前时间

        # if (c - ut).days < 30: #时间差
        #     can_change_nickname = False
        # else:
        #     can_change_nickname = True

        #得到权限
        per = users.get_permission_by_douid(user.douban_id)
        rights = per[0].rights

        #得到提醒
        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_list = ntf_list + mtf_list
        ntf_posts = ntf_posts + mtf_posts
        ntf_users = ntf_users + mtf_users
        notification_num = notification_num+mention_num

        #得到资料设置
        profile = users.get_profile_by_user_id(user.id)
        #得到邮箱验证状态
        confirm = users.get_confirm_email_by_douban_id(user.douban_id)

        return view.base(view.member_setting_profile(user, profile, confirm), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
Example #9
0
    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"}'
Example #10
0
    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": "投票成功"}'
Example #11
0
    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(' ', '&nbsp;').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) + '"}'
Example #12
0
    def GET(self, username, p=1):
        u = users.get_user_by_username(username)
        if u:
            page = int(p)
            perpage = 5
            offset = (page - 1) * perpage

            created_posts = postModel.getCreatedPostsByUserId(u.id, offset, perpage).list()
            nodes = []
            for i in xrange(len(created_posts)):
                nodes += nodeModel.getNodesByNodeId(created_posts[i].nodeId)
            #得到资料
            profile = users.get_profile_by_user_id(u.id)
            #note 跳转到豆瓣
            # raise web.seeother('http://www.douban.com/people/'+ username)
            

            # pf = users.get_profile_by_user_id(u.id)
            # #得到上传的图片数
            # results,num_results = image.query(u.id)
            # #得到喜欢的图片数
            # fav_count = image.GetUserFavCount(u.id)

            # #得到用户上传的图片路径
            # imagePath = image.get_paths_by_id(u.id).list()
            # paths = []
            # for p in imagePath:
            #     paths += p.path.split()
            # #得到图片id
            # imageIDs = image.get_imageID_by_id(u.id).list()
            # img_ids = []
            # for i in imageIDs:
            #     img_ids += str(i.id).split()
            # return view.base(view.member_home(u, pf, paths, img_ids, num_results, fav_count), user, siteName)

            #是否登录,
            if user.is_logged:
                per = users.get_permission_by_douid(user.douban_id)
                rights = per[0].rights
                #得到提醒
                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_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.member_home(u, profile, created_posts, nodes, user, replace_breaks), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
        else:
            raise web.notfound()
Example #13
0
    def GET(self, username, p=1):
        u = users.get_user_by_username(username)
        if u:
            page = int(p)
            perpage = 5
            offset = (page - 1) * perpage

            liked_pids = postModel.getLikedPostsByUserId(
                u.id, offset, perpage).list()

            liked_posts = []
            for i in xrange(len(liked_pids)):
                liked_posts += postModel.getPostsByPostId(liked_pids[i].pid)

            authors = []
            for i in xrange(len(liked_posts)):
                authors += users.get_users_by_id(liked_posts[i].postAuthor)

            nodes = []
            for i in xrange(len(liked_posts)):
                nodes += nodeModel.getNodesByNodeId(liked_posts[i].nodeId)

            #得到资料
            profile = users.get_profile_by_user_id(u.id)

            #是否登录,
            if user.is_logged:
                per = users.get_permission_by_douid(user.douban_id)
                rights = per[0].rights
                #得到提醒
                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_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.member_favorite(u, profile, liked_posts, nodes, authors,
                                     user), user, siteName, rights, ntf_list,
                notification_num, ntf_posts, ntf_users)
        else:
            raise web.notfound()