Ejemplo n.º 1
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)
Ejemplo n.º 2
0
	def get(self):
		uri = self.request.uri
		request = {}
		pin = Pin()
		
		pin_keys = pin.getByCat('All')
		pin_count = len(pin_keys)
		
		query = {}
		query['q'] 		= "public:1"				
		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_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")			
			self.write(callback_response)
		else:			
			marks = ''			
			for _mark_t in marks_dict:				
				marks = self.render_string('mark.html',mark=_mark_t)+marks
			
			dump(marks)
			category = Category()
			cats = category.getCats()
			dump(cats)
			cat_key = 'All'
			
			self.render('index.html',user=self.currentUserInfo(),marks=marks,cats = cats,urlname = cat_key)