コード例 #1
0
ファイル: post.py プロジェクト: naoyeye/rhinoceros
    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) +'"}'
コード例 #2
0
ファイル: member.py プロジェクト: liutaihua/emotion-gallery
    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)
コード例 #3
0
ファイル: member.py プロジェクト: Magic347/rhinoceros
    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()
コード例 #4
0
ファイル: member.py プロジェクト: liutaihua/emotion-gallery
    def GET(self, username, page_num):
        u = users.get_user_by_username(username)
        page = int(page_num)
        perpage = 10
        offset = (page - 1) * perpage

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

        return view.node_list_member_profile_more(u, nodeList)
コード例 #5
0
    def GET(self, username, page_num):
        u = users.get_user_by_username(username)
        page = int(page_num)
        perpage = 10
        offset = (page - 1) * perpage

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

        return view.node_list_member_profile_more(u, nodeList)
コード例 #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)
コード例 #7
0
ファイル: member.py プロジェクト: liutaihua/emotion-gallery
    def GET(self, username, page_num):
        u = users.get_user_by_username(username)
        page = int(page_num)
        perpage = 5
        offset = (page - 1) * perpage

        # url = web.ctx.get('path')
        # if int(url.count('recent')) == 0:
        created_posts = postModel.getCreatedPostsByUserId(u.id, offset, perpage).list()

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

        return view.post_list_member_profile_more(u, created_posts, nodes)
コード例 #8
0
    def GET(self, username, page_num):
        u = users.get_user_by_username(username)
        page = int(page_num)
        perpage = 5
        offset = (page - 1) * perpage

        # url = web.ctx.get('path')
        # if int(url.count('recent')) == 0:
        created_posts = postModel.getCreatedPostsByUserId(
            u.id, offset, perpage).list()

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

        return view.post_list_member_profile_more(u, created_posts, nodes)
コード例 #9
0
ファイル: member.py プロジェクト: liutaihua/emotion-gallery
    def GET(self, username, page_num):
        u = users.get_user_by_username(username)
        page = int(page_num)
        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)

        return view.node_list_contributed_more(nodeList, authors)
コード例 #10
0
ファイル: member.py プロジェクト: Magic347/rhinoceros
    def GET(self, username, page_num):
        u = users.get_user_by_username(username)
        page = int(page_num)
        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)

        return view.post_list_member_like_more(u, liked_posts, nodes, authors)
コード例 #11
0
    def GET(self, username, page_num):
        u = users.get_user_by_username(username)
        page = int(page_num)
        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)

        return view.node_list_contributed_more(nodeList, authors)
コード例 #12
0
    def GET(self, username, page_num):
        u = users.get_user_by_username(username)
        page = int(page_num)
        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)

        return view.post_list_member_like_more(u, liked_posts, nodes, authors)
コード例 #13
0
ファイル: post.py プロジェクト: naoyeye/rhinoceros
    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) + '"}'
コード例 #14
0
ファイル: member.py プロジェクト: liutaihua/emotion-gallery
    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()
コード例 #15
0
ファイル: session.py プロジェクト: frellica/order-taker
def login(username):
    s = get_session()
    for k, v in users.get_user_by_username(username).items():
        s[k] = v
    s.is_logged = True
コード例 #16
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()