Exemplo n.º 1
0
    def get(self):
        user_id = self.current_user["user_id"]
        if user_id not in admin_ids:
            self.write_json()
            return

        share_num = Share.find().count()
        share_state1_num = Share.find({'status': {'$gte': 1}}).count()

        share_with_tag_num = share_num - Share.find({'tags': []}).count()
        share_state1_with_tag_num = share_state1_num - \
            Share.find({'status': {'$gte': 1}, 'tags': []}).count()

        user_num = User.find().count()
        user_rss_num = User.find({'user_rss': {'$ne': ''}}).count()

        like_num = Like.find().count()  # todo
        hit_num = Hit.find().count()  # todo
        hit_num_in_5_day = Hit.find({'hittime': {'$gt': time.time()-86400*5}}).count()
        # 日活
        self.res = {
            'share_num': share_num,
            'share_state1_num': share_state1_num,
            'share_with_tag_num': share_with_tag_num,
            'share_state1_with_tag_num': share_state1_with_tag_num,

            'user_num': user_num,
            'user_rss_num': user_rss_num,

            'like_num': like_num,
            'hit_num': hit_num,
            'hit_num_in_5_day': hit_num_in_5_day,
        }
        self.write_json()
Exemplo n.º 2
0
Arquivo: user.py Projeto: anwen/anwen
 def get(self, name):
     user = User.find_one({"user_domain": name})
     user.user_say = markdown2.markdown(user.user_say)
     user.user_jointime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(user.user_jointime))
     likenum = User.find({"user_id": user._id}).count()
     user.gravatar = get_avatar(user.user_email, 100)
     self.render("userhome.html", user=user, likenum=likenum)
Exemplo n.º 3
0
 def post(self):
     name = self.get_argument("name", '')
     password = self.get_argument("password", '')
     password = hashlib.md5(password).hexdigest()
     email = self.get_argument("email", '')
     domain = self.get_argument("domain", '')
     if domain == '':
         domain = name
     if User.find({'user_email': email}).count() > 0:
         self.write('用户已经存在,请直接登录')
         self.redirect("/login")
     else:
         res = User
         res['id'] = res.find().count() + 1
         res['user_name'] = name
         res['user_pass'] = password
         res['user_email'] = email
         res['user_domain'] = domain
         res.new(res)
         user = {'user_id': res.id,
                 'user_name': res.user_name,
                 'user_email': res.user_email,
                 'user_domain': res.user_domain}
         self.set_secure_cookie("user", tornado.escape.json_encode(user))
         self.redirect(self.get_argument("next", "/"))
Exemplo n.º 4
0
    def get(self, node):
        page = self.get_argument("page", 1)
        share_res = Share.find({'sharetype': node}).sort(
            '_id', DESCENDING).limit(10).skip((int(page) - 1) * 10)
        pagesum = (share_res.count() + 9) / 10

        shares = []
        for share in share_res:
            user = User.by_sid(share.user_id)
            share.name = user.user_name
            share.published = time.strftime(
                '%Y-%m-%d %H:%M:%S', time.localtime(share.published))
            share.domain = user.user_domain
            share.markdown = filter_tags(
                markdown2.markdown(share.markdown))[:100]
            share.gravatar = get_avatar(user.user_email, 16)
            shares.append(share)
        members = User.find().sort('_id', DESCENDING).limit(20)
        members_dict = []
        for member in members:
            member.gravatar = get_avatar(member.user_email, 25)
            members_dict.append(member)
        node_about = options.node_about[node]
        self.render(
            "node.html", shares=shares, members=members_dict,
            pagesum=pagesum, page=page, node=node, node_about=node_about)
Exemplo n.º 5
0
Arquivo: users.py Projeto: anwen/anwen
    def get(self):
        users = User.find({'user_leaf': {'$gt': 20}}).sort('user_leaf', -1)
        l_users = []
        for user in users:
            # print(user)
            # user.user_say = markdown2.markdown(user.user_say)
            # user.user_jointime = time.strftime(
            #     '%Y-%m-%d %H:%M:%S', time.localtime(user.user_jointime))
            # likenum = User.find({'user_id': user._id}).count()
            # user.gravatar = get_avatar(user.user_email, 100)
            # contents = Share.find({'user_id': user.id})
            # if contents.count():
            auser = {}
            auser['user_domain'] = user.user_domain
            auser['user_name'] = user.user_name
            auser['article_num'] = int(
                (user.user_leaf - 20) / 10)  # contents.count()

            if user.user_email.endswith('@wechat'):
                auser['user_img'] = options.site_url + get_avatar_by_wechat(
                    user._id)
            if user.user_email.endswith('@anwensf.com'):
                auser['user_img'] = options.site_url + get_avatar_by_feed(
                    user.id)
            else:
                auser['user_img'] = options.site_url + get_avatar(
                    user.user_email, 100)

            l_users.append(auser)

        self.render('users.html', users=l_users)
Exemplo n.º 6
0
 def get(self, name):
     user = User.find_one({'user_domain': name})
     user.user_say = markdown2.markdown(user.user_say)
     user.user_jointime = time.strftime('%Y-%m-%d %H:%M:%S',
                                        time.localtime(user.user_jointime))
     likenum = User.find({'user_id': user._id}).count()
     user.gravatar = get_avatar(user.user_email, 100)
     self.render('userhome.html', user=user, likenum=likenum)
Exemplo n.º 7
0
 def get(self, name):
     user = User.find_one({'user_domain': name})
     user.user_jointime = time.strftime(
         '%Y-%m-%d %H:%M:%S', time.localtime(user.user_jointime))
     likes = User.find({'user_id': user._id})
     likenum = likes.count()
     for like in likes:
         share = Share.by_id(like.share_id)
         like.title = share.title
         like.id = share.id
         like.type = share.sharetype
     user.gravatar = get_avatar(user.user_email, 100)
     self.render("userlike.html", user=user, likenum=likenum, likes=likes)
Exemplo n.º 8
0
Arquivo: user.py Projeto: anwen/anwen
 def get(self):
     members = User.find()
     self.render("member.html", members=members)
Exemplo n.º 9
0
# Address.add_address(user, "streetTest", "townTest", "postalCodeTest")
# EMailAddress.add_emailAddress(user, "mailTest")
# PhoneNumber.add_phone(user, "phoneTest1")
# PhoneNumber.add_phone(user, "phoneTest2")
#
# user1 = User.add("FirstNameQwerty", "LastNameQwerty")
# Address.add_address(user1, "streetQwerty", "townQwerty", "postalCodeQwerty")
# EMailAddress.add_emailAddress(user1, "mailQwerty")
# PhoneNumber.add_phone(user1, "phoneQwerty1")
# PhoneNumber.add_phone(user1, "phoneQwerty2")
#
#
# user.create_connection(user1)


users = User.find(['FirstName25', 'FirstNameTest', 'FirstNameQwerty'])

print()

for i in range(len(users)):
    if users[i] is not None:
        print(f"firstName: {users[i].firstName}")
        print(f"lastName: {users[i].lastName}")
        print(f"Address: {users[i].address}")
        print(f"eMailAddress: {users[i].eMailAddresses}")
        print(f"phoneNumbers: {users[i].phoneNumber}")

        for usr in range(len(users[i].usersList)):
            print(f"Connected users: {users[i].usersList[usr].firstName}")

    print()
Exemplo n.º 10
0
 def get(self):
     members = User.find()
     self.render('member.html', members=members)
Exemplo n.º 11
0
Arquivo: user.py Projeto: anwen/anwen
    def get(self, name):
        user = User.find_one({'user_domain': name})
        user.user_say = markdown2.markdown(user.user_say)
        user.user_jointime = time.strftime('%Y-%m-%d %H:%M:%S',
                                           time.localtime(user.user_jointime))
        likenum = User.find({'user_id': user._id}).count()
        user.gravatar = get_avatar(user.user_email, 100)
        shares = Share.find({
            'user_id': user.id
        }, {
            'markdown': 0,
            'summary': 0
        }).sort('_id', -1).limit(100)

        likes = set()
        dislikes = set()
        collects = set()
        if self.current_user:
            user_id = self.current_user["user_id"]
            _likes = Like.find({
                'entity_type': 'share',
                'user_id': user_id
            }, {
                '_id': 0,
                'entity_id': 1,
                'likenum': 1,
                'dislikenum': 1
            })
            _likes = list(_likes)
            print(_likes[0])
            likes = set(i.entity_id for i in _likes if i.likenum > 0)
            dislikes = set(i.entity_id for i in _likes if i.dislikenum > 0)
            collects = Collect.find(
                {
                    'entity_type': 'share',
                    'user_id': user_id
                }, {
                    '_id': 0,
                    'entity_id': 1,
                    'collectnum': 1
                })
            collects = set(i.entity_id for i in collects if i.collectnum > 0)

        l_share = []
        print(shares[0])
        for share in shares:
            # d_share = dict(share)
            # d_share = share
            # if self.current_user:
            #     user_id = self.current_user["user_id"]
            #     like = Like.find_one(
            #         {'entity_id': share.id, 'entity_type': 'share', 'user_id': user_id})
            #     collect = Collect.find_one(
            #         {'entity_id': share.id, 'entity_type': 'share', 'user_id': user_id})
            #     d_share.is_liking = bool(like.likenum) if like else False
            #     d_share.is_disliking = bool(like.dislikenum) if like else False
            #     d_share.is_collecting = bool(collect.collectnum) if collect else False
            # print(d_share.id, len(likes))
            share.is_liking = True if likes and share.id in likes else False
            share.is_disliking = True if dislikes and share.id in dislikes else False
            share.is_collecting = True if collects and share.id in collects else False
            l_share.append(share)

        self.render('userhome.html',
                    user=user,
                    shares=l_share,
                    is_login=bool(self.current_user),
                    likenum=likenum)
Exemplo n.º 12
0
    def get(self):
        ver = self.get_argument("ver", 3)
        name = self.get_argument("name", '')
        sid = self.get_argument("id", 0)
        ver = int(ver)
        sid = int(sid)
        # parents [0]
        if name or sid:
            # 具体某个标签
            if not name and sid:
                tag = Tag.by_sid(sid)
                name = tag['name']
            self.res = d_tags_v3.get(name, {})

            if self.res:
                parents = d_tags_parents.get(self.res['name'], {})
                node = d_tags_v3.get(parents, {})
                self.res['parents'] = copy.deepcopy(node)
                self.res['parents'].pop('subs')

                brothers = []
                for sub in copy.deepcopy(node)['subs']:
                    sub.pop('subs')
                    brothers.append(sub)
                self.res['brothers'] = brothers
                if parents:
                    parents_p = d_tags_parents.get(parents, {})
                    if parents_p:
                        node = d_tags_v3.get(parents_p, {})

                        self.res['parents']['parents'] = copy.deepcopy(node)
                        self.res['parents']['parents'].pop('subs')

                        parents_pp = d_tags_parents.get(parents_p, {})
                        if parents_pp:
                            node = d_tags_v3.get(parents_pp, {})
                            self.res['parents']['parents'][
                                'parents'] = copy.deepcopy(node)
                            self.res['parents']['parents']['parents'].pop(
                                'subs')

                    self.res['articleNumber'] = Share.count_by_tag(
                        self.res['name'])
                    self.res['followerNumber'] = User.find({
                        'user_tags': {
                            '$in': [name]
                        }
                    }).count()
                    self.res['isFollowing'] = False
                    user_id = self.current_user[
                        "user_id"] if self.current_user else None
                    if user_id:
                        user = User.by_sid(user_id)
                        if user:
                            # model1
                            self.res['isFollowing'] = name in user['user_tags']
                            # model2 查看like 表
                            # self.res['isFollowing'] = name in user['user_tags']

                    print("self.res['followerNumber']",
                          self.res['followerNumber'])
                tag = Tag.by_name(self.res['name'])

                if tag:
                    self.res['id'] = tag['id']
            else:
                self.res['id'] = -1
        else:
            # 从根节点开始
            if ver == 3:
                self.res = d_tags_v2
                self.res['parents'] = {}  # root
                self.res['articleNumber'] = Share.count_by_tag(
                    self.res['name'])
                tag = Tag.by_name(self.res['name'])  # 7491
                self.res['id'] = -1
                if tag:
                    self.res['id'] = tag['id']
            elif ver == 2:
                self.res = d_tags_v2
                if self.current_user and 'user_id' in self.current_user:
                    user = User.by_sid(self.current_user['user_id'])
                    self.res['watched_tags'] = user['user_tags']
            else:
                self.res = d_tags
        self.write_json()