예제 #1
0
파일: user.py 프로젝트: aviatorBeijing/ptpy
 def post(self):    
     email     = self.get_argument("email",None)
     password  = self.get_argument("password",None)        
     import hashlib
     errMsg = None
     if email is None:
         errMsg = "Email不能为空"
         return self.render('login.html',user=self.currentUserInfo(),errMsg=errMsg)
     if password is None:
         errMsg = "Email不能为空"
         return self.render('login.html',user=self.currentUserInfo(),errMsg=errMsg)
     
     user_key = hashlib.md5(email).hexdigest()
     user = User()
     user_data = user.getDetail(user_key)
     
     if user_data is None:            
         errMsg = "用户不存在"
     else:
         if hashlib.md5(password).hexdigest() != user_data['password']:
             errMsg = "用户名或密码不正确"      
         else:
             urlname = user_data['nickname']                
             self.set_secure_cookie('user_email',user_data['email'])
             self.set_secure_cookie('user_nickname',urlname)
             self.set_secure_cookie('user_urlname',urlname)
             self.set_secure_cookie('user_key',user_key)
             self.set_secure_cookie('user_avatar',user_data['avatar'])
             #print "login succ!"
             return self.redirect('/')
             
     self.render('login.html',user=self.currentUserInfo(),errMsg=errMsg)
예제 #2
0
 def get(self,key):
     uri = self.request.uri
     request = {}
     pin = Pin()
     
     pin_keys = pin.getByKeyValues("board",key)
     pin_count = len(pin_keys)
     
     query = {}
     query['q']         = "board:%s" % key    
             
     query['start']  = "0"
     query['rows']   = globalSetting['max_index_pin_rows']
     query['sort']   = "createTime"
     
     if "page" in uri:
         request = urldecode(uri)
         page = int(request['page'])
         query['start']  = query['rows']*page
         if pin_count < query['rows']*page:
             return ''
     
     pin_data = pin.solr(query)
     print len(pin_data)
     
     marks_dict = pin.formatPins(pin_data)        
     
     if request:
         #print request['callback']
         #print request['page']            
         callback_result = {
                         'filter':'pin:index',
                         'pins':marks_dict
                         }
         
         callback_response = "%s(%s)" % (request['callback'],json.dumps(callback_result))
         self.set_header("Content-Type", "text/html; charset=utf-8")            
         return self.write(callback_response)
     else:
         marks = ''            
         for _mark_t in marks_dict:                
             marks = self.render_string('mark.html',mark=_mark_t)+marks
         board = Board()
         user = User()
         category = Category() 
  
         board_data = board.get(key)
         
         b_user = user.getDetail(board_data['user'])
         b_category = category.get(board_data['category'])
         b_keys = board.getByKeyValues("user", board_data['user'])
         
         if key in b_keys:
             b_keys.remove(key)
             
         b_boards = board.all(b_keys)
     
         self.render('board_pins_list.html',f_board = self.formatFollowBoardData(key), b_boards= b_boards,b_category = b_category,b_user=b_user,user=self.currentUserInfo(),board = board.get(key),marks=marks)
예제 #3
0
    def get(self):
        uri = self.request.uri
        request = {}
        board = BoardFollow()
        
        #in_keys = board.allKey()
        user_key = self.get_secure_cookie("user_key")
        query = {}
        query['q']         = "user:%s" % user_key
                
        query['start']  = "0"
        query['rows']   = globalSetting['max_index_board_rows']
        query['sort']   = "follow"
        
        if "page" in uri:
            request = urldecode(uri)
            page = int(request['page'])
            query['start']  = query['rows']*page
            #if pin_count < query['rows']*page:
            #    return ''
        
        board_data = board.solr(query)
        #print len(board_data)

        boards_dict = board.formatBoards(board_data)
        
        if request:
            #print request
            callback_result = {
                            'filter':'board:index',
                            'boards':boards_dict
                            }
            
            callback_response = "%s(%s)" % (request['callback'],json.dumps(callback_result))
            self.set_header("Content-Type", "text/html; charset=utf-8")            
            return self.write(callback_response)
        else:
            boards = ''            
            for _board_t in boards_dict:                
                boards = self.render_string('board_unit.html',board=_board_t) + boards
                
            user_key = self.get_secure_cookie("user_key")
            user = User()
            userInfo = user.getDetail(user_key)
            from models.userFollow import UserFollow
            userFollow = UserFollow()
            counts = {}
            pinM = Pin()
            boardM = Board()
            counts['fans'] = len(userFollow.getByKeyValues("follow", user_key)) 
            counts['pins'] = len(pinM.getByKeyValues("user", user_key)) 
            counts['boards'] = len(boardM.getByKeyValues("user", user_key)) 
            
            self.render('board_follow.html',counts=counts,userInfo = userInfo,user=self.currentUserInfo(),boards=boards) 
예제 #4
0
파일: comment.py 프로젝트: sousajmr/ptpy
    def getByPin(self, key):
        query = {}
        query["q"] = "pin:%s" % key
        query["sort"] = "createTime"
        comment_data = self.solr(query)

        # comment_keys = self.getByKeyValues('pin', key)
        # comment_data = self.all(comment_keys)
        user = User()
        res = []
        for row in comment_data:
            row["userInfo"] = user.getDetail(row["user"])
            res.append(row)
        return res
예제 #5
0
 def post(self):
     import hashlib,time
     user_key      = self.get_secure_cookie('user_key')        
     pin_key       = self.get_argument("pinid",None)
     nickname      = self.get_secure_cookie('user_nickname')
     rawtext       = self.get_argument("text",None)
     res = {}
     if rawtext is None:
         res['code'] = 1
         res['data'] = "请输入评论"
         body = json.dumps(res)
         self.set_header("Content-Type", "text/json; charset=UTF-8")
         self.write(body)
     
     comment = Comment()
     _tmp = "%s%s" % (user_key,rawtext)
     key = comment.genKey(_tmp)
     
     comment.key = key
     comment.data['rawtext'] = rawtext
     comment.data['user']    = user_key
     comment.data['pin']     = pin_key
     comment.data['createTime']     = int(time.time())
     
     try: 
         comment.post()
     except Exception as what:
         print what
         res['code'] = 1
         res['data'] = what
     else:            
         res['code'] = 0
         res['data'] = "sucess"
         obj  = {}
         user = User()
         obj['key']        = comment.key
         obj['userInfo']   = user.getDetail(user_key)
         obj['rawtext']    = comment.data['rawtext']
         obj['createTime'] = comment.data['createTime']
         print obj['userInfo']
         res['obj'] = obj
       
     body = json.dumps(res)
     print body
     self.set_header("Content-Type", "text/json; charset=UTF-8")
     self.write(body)
예제 #6
0
파일: pin.py 프로젝트: aviatorBeijing/ptpy
 def getPinDetail(self,key):        
     board = Board()
     user = User()
     thumb = Thumb()        
     pic = Pic()        
     comment = Comment()    
     
     marks_dict = []
     pin = self.get(key)
     _pin = {}
     _pin['pin']               = self.get(key)
     _pin['user']              = user.getDetail(pin['user'])
     _pin['pin']['pic']        = pic.get(pin['key'])['url']
     
     
     _pin['board']             = board.getDetailWithPinThumb(pin['board']) 
     
     _pin['comments']         = comment.getByPin( pin['key'])           
         
     return _pin
예제 #7
0
파일: pin.py 프로젝트: aviatorBeijing/ptpy
 def formatPins(self,data):        
     board = Board()
     user = User()
     thumb = Thumb()
     comment = Comment()    
     
     marks_dict = []
     
     for pin in data:
         _pin = {}
         _pin['pin']               = pin
         _pin['user']              = user.getDetail(pin['user'])
         _pin['thumb']             = thumb.get(pin['key'])
         
         _pin['board']             = board.getDetail(pin['board']) 
         #print _pin['board']
         _pin['comments']         = comment.getByPin( pin['key'])
         
         marks_dict.append(_pin)
         
     return marks_dict