Example #1
0
 def post(self):
     book_id = self.parse_body('bookId', '')
     user_id = self.current_user_my
     user = User.objects(index=user_id['userId']).first()
     print 'iss: ', user.collections, book_id
     user.collections.append(int(book_id))
     print user.collections
     user.save()
     user_info_redis(0)
     self.write({'errorCode': 10000})
Example #2
0
def user_info_redis(user_type, redis_cli=None):
    if redis_cli is None:
        redis_cli = tornadoredis.Client()
       
    ino_type_ = 'follows.' if user_type else 'collections.'
    all_user = User.objects().all()
    with redis_cli.pipeline() as pipe:
        for i in all_user:
            if user_type == 1:
                for k in i.follows:
                    print i.index, k
                    pipe.sadd('follows.'+ str(i.index),  int(k))
            else:
                for k in i.collections:
                    pipe.sadd('collections.'+ str(i.index),  int(k))
        pipe.execute()
    print '\ninit redis complated\n'
Example #3
0
    def post(self):
        import datetime
        author = self.parse_body('author', '')
        com_time = datetime.datetime.now()
        theme = self.parse_body('theme', '')
        comment = self.parse_body('comment', '')
        book_id = self.parse_body('bookId', '')
        nickname = User.objects(index=int(author)).first().nickname
        com = Comments(author=author, nickname=nickname, com_time=com_time, theme=theme,\
                 comment=comment)
        com.save()
        print 'book_Id: ', book_id

        print 'debug: ',
        t= Books.objects(index=int(book_id)).first()
        t.comments.append(com)
        t.save()
        self.write({'errorCode': 10000})
Example #4
0
    def post(self):
        nickname = self.parse_body('username', '')
        user = User.objects(nickname=nickname).first()
        email = self.parse_body('email', '')
        kw = {}
        new_pass = self.parse_body('newPass')
        if new_pass:
            kw.update({'password': new_pass})
        note = self.parse_body('note', '')
        if note:
            kw.update({'note': note})
        level = self.parse_body('level')
        telnec = self.parse_body('telnec')
        res = ""
        for i in telnec:
            res = res + str(i) + str(level) + ':'
        if res:
            kw.update({'tags': res[0: -1]})

        user.update_info(**kw)

        self.write({'errorCode': 10000})
Example #5
0
 def get_user(cls, user_id=None, account=None):
     if user_id is not None and not isinstance(user_id, ObjectId):
         user_id = ObjectId(user_id)
     match = dict(id=user_id) if user_id else dict(account=account)
     user = User.objects(match).first()
     return user
Example #6
0
 def get(self):
     url = self.request.path
     import re
     nickname = re.search(r'/\w{1,32}/', url).group(0)[1:-1]
     user = User.objects(nickname=nickname).first()
     self.render('index/user_info.html', user=user, username='******')