def get(self,key): uri = self.request.uri request = {} board = Board() pin_keys = board.allKey() pin_count = len(pin_keys) query = {} query['q'] = "user:%s" % 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'] #print request['page'] 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: user = User() boards = '' for _board_t in boards_dict: boards = self.render_string('board_unit.html',board=_board_t) + boards 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_board.html',counts=counts,u_user=u_user,user=self.currentUserInfo(),boards=boards)
def get(self,key): user_key = self.get_secure_cookie("user_key") board = Board() query = {} query['q'] = "user:%s" % user_key _data = board.solr(query) thumb = Thumb() pic = Pic() pic_url = pic.get(key)['url'] thumb_url = thumb.get(key)['url'] self.render('repin.html',boards = _data,pic_url=pic_url,thumb_url=thumb_url)
def get(self): uri = self.request.uri request = {} board = Board() pin_keys = board.allKey() query = {} query['q'] = "public:1" 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 self.render('board_pop.html',user=self.currentUserInfo(),boards=boards)
def post(self): uri = self.request.uri avatar_sha1=self.get_argument("f_file.sha1",None) if avatar_sha1: user_key = self.get_secure_cookie("user_key") res = {} upload_file_name=self.get_argument("f_file.name",None) ext = upload_file_name.split('.')[1] img_path_t=os.path.join("/tmp/upload_temp_dir/",str(avatar_sha1)) img_path = "%s.%s" % (img_path_t,ext) upload_file_path=self.get_argument("f_file.path",None) os .rename(upload_file_path,img_path) client = Fdfs_client(globalSetting['fdfs_client_conf']) ret = client.upload_by_filename(img_path) remote_file_id = ret['Remote file_id'] storage_ip = ret['Storage IP'] pic_url = "http://%s:%d/%s" % (storage_ip,globalSetting['fdfsPort'],remote_file_id) print pic_url from models.avatar import Avatar avatar = Avatar() avatar.key = user_key avatar.data['url'] = pic_url avatar.post() res['avatar'] = pic_url res['error'] = '' return self.dumpJson(res) upload_file_sha1=self.get_argument("ifile.sha1",None) #upload_file_size=self.get_argument("ifile.size",None) upload_file_path=self.get_argument("ifile.path",None) upload_file_name=self.get_argument("ifile.name",None) print upload_file_name ext = upload_file_name.split('.')[1] img_path_t=os.path.join("/tmp/upload_temp_dir/",str(upload_file_sha1)) img_path = "%s.%s" % (img_path_t,ext) img_path_170x170 = "%s_170x170.%s" % (img_path_t,ext) try: i=Img() i.open('/usr/bin') i.convert_resize(input_file=upload_file_path,output_file=img_path,output_size="500x") i.convert_thumbnail(input_file=img_path,output_file=img_path_170x170,output_size="170x170") except Exception as what: #data=file(upload_file_path,'rb').close() print what pass client = Fdfs_client(globalSetting['fdfs_client_conf']) ret = client.upload_by_filename(img_path) remote_file_id = ret['Remote file_id'] storage_ip = ret['Storage IP'] pic_url = "http://%s:%d/%s" % (storage_ip,globalSetting['fdfsPort'],remote_file_id) ret = client.upload_by_filename(img_path_170x170) remote_file_id = ret['Remote file_id'] storage_ip = ret['Storage IP'] thumb_url = "http://%s:%d/%s" % (storage_ip,globalSetting['fdfsPort'],remote_file_id) user_key = self.get_secure_cookie("user_key") board = Board() query = {} query['q'] = "user:%s" % user_key _data = board.solr(query) self.render('upload_form.html',boards = _data,pic_url=pic_url,thumb_url=thumb_url)