Beispiel #1
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)
Beispiel #2
0
	def get(self,cat_key):	
		if cat_key == 'All':
			self.redirect('/')
		else:
			uri = self.request.uri
			request = {}
			pin = Pin()
			
			pin_keys = pin.getByCat(cat_key)
			pin_count = len(pin_keys)
			
			query = {}
			query['q'] 		= "category:%s" % cat_key
					
			query['start']  = "0"
			query['rows']   = globalSetting['max_index_pin_rows']
			query['sort']   = "createTime"
			
			if "page" in uri:
				request = urldecode(uri)
				print request
				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")			
				return self.write(callback_response)
			else:
				marks = ''			
				for _mark_t in marks_dict:				
					marks = self.render_string('mark.html',mark=_mark_t)+marks
				if marks == '':
					marks = """
					<div class="pin category wfc isotope-item" style="margin-bottom: 15px; position: absolute; left: 0px; top: 0px; -webkit-transform: translate3d(0px, 0px, 0px); ">
					NO PINS
					</div>
					"""
				category = Category()
				cats = category.getCats()
				
				self.render('index.html',user=self.currentUserInfo(),marks=marks,cats = cats,urlname = cat_key)		
Beispiel #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) 
Beispiel #4
0
 def get(self):
     query = {}
     query['q']         = "public:1"                
     query['start']  = "0"
     query['rows']   = globalSetting['max_index_pin_rows']
     query['sort']   = "createTime"
     pin = Pin()
     pin_data = pin.solr(query)
     #print len(pin_data)        
     _data = pin.formatPins(pin_data)
     
     self.render('manager/pin.html',data=_data)
Beispiel #5
0
 def get(self,key):
     uri = self.request.uri
     request = {}
     pin = Pin()
     
     pin_keys = pin.getByKeyValues("user",key)
     pin_count = len(pin_keys)
     
     query = {}
     query['q']         = "user:%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)
     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")            
         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_pins.html',counts=counts,u_user=u_user,user=self.currentUserInfo(),board = board.get(key),marks=marks)
Beispiel #6
0
 def post(self):
     import time        
     board_key    = self.get_argument("board",None)
     pic_url      = self.get_argument("pic_url",None)
     thumb_url    = self.get_argument("thumb_url",None)
     content      = self.get_argument("content",None)        
     
     pin       = Pin()
     thumb     = Thumb()
     pic       = Pic()
     board     = Board()
     
     board.data  =board.get(board_key)
     
     user_key = self.get_secure_cookie('user_key')
     
     _tmp = "%s%s" % (content,user_key)
     pin_key = pin.genKey(_tmp)
     
     if pin_key not in board.data['pins']:
         board.data['pins'].append(pin_key)
     board.key      = board.data['key']
     
     pin.key = pin_key
     
     pin.data['rawtext'] = content
     pin.data['user']    = user_key
     pin.data['board']   = board_key
     pin.data['category']   = board.data['category']
     pin.data['createTime'] = int(time.time())
     
     pic.key = pin_key
     pic.data['url'] = pic_url
     
     thumb.key = pin_key
     thumb.data['url'] = thumb_url
     
     try:
         board.put()
         pin.post()
         pic.post()
         thumb.post()
                   
     except Exception as what:
         print what
         self.write(what)
     else:
         self.redirect('/mark/%s/' % pin_key)   
Beispiel #7
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)		
Beispiel #8
0
    def factory(event):
        """Creates a Pin with Attachments based on the pin_added event sent by
        the Slack events API.

        Args:
            event (dict): A dict representation of the JSON sent by the Slack
            events API upon the creation of a pin_added event.

        Returns:
            pins4days.models.pin.Pin: A Pin model.
        """
        if event['type'] == 'event_callback':
            message = event['event']['item']['message']
            pinned_info = event['event']['pinned_info']
            attachments = message[
                'attachments'] if 'attachments' in message else []
            attachment_entities = [
                MessageAttachment.factory(a) for a in attachments
            ]
            pin = Pin.create(text=message['text'],
                             author_id=message['user'],
                             pinner_id=pinned_info['pinned_by'],
                             channel_id=pinned_info['channel'],
                             pinned_ts=pinned_info['pinned_ts'],
                             created_ts=event['event']['item']['created'],
                             attachments=attachment_entities,
                             ts=message['ts'])
        elif event['type'] == 'message':
            message = event['message']
            attachments = message[
                'attachments'] if 'attachments' in message else []
            attachment_entities = [
                MessageAttachment.factory(a) for a in attachments
            ]
            pin = Pin.create(text=message['text'],
                             author_id=message['user'],
                             pinner_id=event['created_by'],
                             channel_id=event['channel'],
                             pinned_ts=None,
                             created_ts=event['created'],
                             attachments=attachment_entities,
                             ts=message['ts'])
        else:
            raise NotImplementedError(
                'Slack resource of type "{}" unrecognized'.format(
                    event['type']))
        return pin
Beispiel #9
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)
Beispiel #10
0
 def formatPins(self,data):    
     pin = Pin()    
     board = Board()
     user = User()
     thumb = Thumb()
     comment = Comment()    
     
     marks_dict = []
     
     for pin_row in data:
         _pin = {}
         _pin['pin']               = pin.get(pin_row['pin'])
         _pin['user']              = user.getDetail(pin_row['user'])
         _pin['thumb']             = thumb.get(pin_row['pin'])            
         _pin['board']             = board.getDetail(_pin['pin']['board']) 
         #print _pin['board']
         _pin['comments']         = comment.getByPin(pin_row['pin'])
         
         marks_dict.append(_pin)
         
     return marks_dict
Beispiel #11
0
    def get(self):
        uri = self.request.uri
        request = {}
        pin = Pin()
        request = urldecode(uri)
        q = request['q']    
        
        query = {}
        query['q']         = "rawtext:*%s*" % q                
        #query['start']  = "0"
        #query['rows']   = globalSetting['max_index_pin_rows']
        query['sort']   = "like"
        
        #if "page" in 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

        self.render('pins_search.html',query = q,user=self.currentUserInfo(),marks=marks)  
Beispiel #12
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)
Beispiel #13
0
 def get(self,key):
     obj = Pin() 
     obj.delete(key)