Пример #1
0
 def get(self,key):
     user_key = self.get_secure_cookie("user_key")
     pinLike = PinLike()
     l_key = hashlib.md5("%s%s" % (user_key,key)).hexdigest()
     res = {} 
     res['code'] = 0
     res['msg'] = "成功"
     pinLike.delete(l_key)
     res_str = json.dumps(res)
     self.write(res_str)
Пример #2
0
 def get(self,key):
     user_key = self.get_secure_cookie("user_key")
     print user_key
     pinLike = PinLike()
     l_key = hashlib.md5("%s%s" % (user_key,key)).hexdigest()
     
     l_data = pinLike.get(l_key)     
     #return self.dumpJson(l_data) 
     res = {}  
     if l_data:
         res['code'] = 1
         res['msg'] = "您已喜欢过"
     else :
         pinLike.key = l_key
         pinLike.data['user'] = user_key
         pinLike.data['pin'] = key
         pinLike.data['createTime'] = int(time.time())
         pinLike.post()
         pin =Pin()
         data = pin.get(key)
         pin.key = key
         pin.data = data
         pin.data['like'] = int(data['like']) + 1
         pin.put()        
         dump(data)
         res['code'] = 0
         res['msg'] = "成功"
     res_str = json.dumps(res)
     self.write(res_str)
Пример #3
0
 def get(self,key):
     uri = self.request.uri
     request = {}
     
     from models.pinLike import PinLike
     pinLike = PinLike()
     query = {}
     query['q']         = "user:%s" % key    
     query['start']  = "0"
     query['rows']   = globalSetting['max_index_pin_rows']
     query['sort']   = "createTime"
     
     pin_keys = pinLike.getByKeyValues("user",key)        
     pin_count = len(pin_keys)        
     
     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 = pinLike.solr(query)
     marks_dict = pinLike.formatPins(pin_data)    
     
     if request:
         #print request
         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:
         board = Board()
         user = User()
         marks = ''
         for _mark_t in marks_dict:
             marks = self.render_string('mark.html',mark=_mark_t)+marks
         u_user = user.getInfo(key)
         userFollow = UserFollow()
         counts = {}
         counts['follow'] = len(userFollow.getByKeyValues("user", key))
         
         counts['fans'] = len(userFollow.getByKeyValues("follow", key)) 
         self.render('user_likes.html',counts= counts,u_user=u_user,user=self.currentUserInfo(),board = board.get(key),marks=marks)
Пример #4
0
 def get(self,key):        
     pin = Pin()
     pin_data = pin.getPinDetail(key)
     
     user_key = self.get_secure_cookie("user_key")
     _l_data = {}
     _h_data = {}
     if user_key:
         pinLike = PinLike()
         pinHate = PinHate()
         
         l_key = hashlib.md5("%s%s" % (user_key,key)).hexdigest()
         h_key = l_key
         l_data = pinLike.get(l_key)
         h_data = pinHate.get(h_key)
         
         
         if l_data:
             _l_data['str'] = "取消喜欢"
             _l_data['rel'] = 1
         else:
             _l_data['str'] = "喜欢"
             _l_data['rel'] = 0
             
         
         if h_data:
             _h_data['str'] = "取消讨厌"
             _h_data['rel'] = 1
         else:
             _h_data['str'] = "讨厌"
             _h_data['rel'] = 0
     else:
         _l_data['str'] = "喜欢"
         _l_data['rel'] = 0
         _h_data['str'] = "讨厌"
         _h_data['rel'] = 0
     #print pin_data
     self.render('mark_template.html',user=self.currentUserInfo(),mark=pin_data,like = _l_data,hate = _h_data)