def send_comment(self,uid,post_id,comm_content): """ function : 评论说说 input param: uid: post_id 说说id 评论主键 comm_content 评论内容 return: comm_id 评论pk """ comm_id = PostComModel().send_comment(uid,post_id,comm_content) PostModel().comm_num_oper(post_id,1)#更新说说评论总数 PostModel().update_comm_list(uid,post_id,comm_content) #更新post集合中的第一页评论 return comm_id
def get_post_info(self,uid,post_id): """ 获取说说详情 """ post_info = PostModel().get_post_info(post_id) post_info['post_id'] = str(post_info['_id']) current_time = PublicFunc.get_current_stamp() post_info['time'] = PublicFunc.time_format_span(post_info['time'],current_time) del post_info['_id'] user_info = UsersModel().get_import_user_info(post_info['uid'],['avatar','nickname'])#获取发说说的人的信息 post_info['avatar'] = user_info['avatar'] post_info['nickname'] = user_info['nickname'] if user_info['nickname'] else options.default_nick_name comm_list = post_info['comm_list'] for comm in comm_list: comm['time'] = PublicFunc.time_format_span(comm['time'],current_time) comm_user_info = UsersModel().get_import_user_info(comm['uid'],['avatar','nickname'])#获取评论说说的人的信息 comm['avatar'] = comm_user_info['avatar'] comm['nickname'] = comm_user_info['nickname'] if comm_user_info['nickname'] else options.default_nick_name love_list = post_info['love_list'] for lover in love_list: lover_info = UsersModel().get_import_user_info(lover['uid'],['avatar','nickname'])#获取评论说说的人的信息 lover['avatar'] = lover_info['avatar'] # post_info['pic_list'] = [options.ipnet + pic for pic in post_info['pic_list']] # post_info['pic_list'] = [{'ori_pic':options.ipnet + pic,'thumb_pic':options.ipnet+options.post_thumb_save_path+'t'+pic[-17:]} for pic in post_info['pic_list']] post_info['pic_list'] = [{'ori_pic':options.ipnet + pic,'thumb_pic':options.ipnet+pic} for pic in post_info['pic_list']] #man has love? post_info['has_love'] = 1 if PostLoveModel().judge_post_love(uid,post_info['post_id']) else 0 if int(post_info['uid']) == int(uid): post_info['has_follow'] = '' else:post_info['has_follow'] = '已关注' if FollowModel().get_follow_status(uid,post_info['uid']) else '关注' # post['has_follow'] = '已关注' if FollowModel().get_follow_status(uid,post['uid']) else '关注' return post_info
def get_post_list(self,uid,page): """ function: 获取互动列表 """ post_list = PostModel().get_post_list(page) current_time = PublicFunc.get_current_stamp() for post in post_list: post['post_id'] = str(post['_id']) post['have_love'] = 1 if PostLoveModel().judge_post_love(uid,post['_id']) else 0 del post['_id'] # post['pic_list'] = [{'ori_pic':options.ipnet + pic,'thumb_pic':options.ipnet+options.post_thumb_save_path+'t'+pic[-17:]} for pic in post['pic_list']] post['pic_list'] = [{'ori_pic':options.ipnet + pic,'thumb_pic':options.ipnet+pic} for pic in post['pic_list']] post['time'] = PublicFunc.time_format_span(post['time'],current_time) user_info = UsersModel().get_import_user_info(post['uid'],['avatar','nickname']) # qz = user_info['avatar'][:4] post['avatar'] = user_info['avatar'] post['nickname'] = user_info['nickname'] if user_info['nickname'] else options.default_nick_name post['self_post'] = 0 if post['uid'] == int(uid): post['has_follow'] = '' post['self_post'] = 1 else: post['has_follow'] = '已关注' if FollowModel().get_follow_status(uid,post['uid']) else '关注' return post_list
def get_recommend_list(self,uid): """ 获取推荐的关注列表 """ recommend_user_list = PostModel().recommend_user(uid) for recommend_user in recommend_user_list: user_info = UsersModel().get_import_user_info(recommend_user['uid'],['avatar','nickname']) recommend_user['nickname'] = user_info['nickname'] if user_info['nickname'] else options.default_nick_name run_data = RunDataModel().get_user_sum_run(uid) if run_data: duration = round(run_data['duration']/3600.0,1) distance = round(run_data['distance']/1000.0,1) recommend_user['run'] = '我总共运动了%sh,运动了%sKm' % (duration,distance) else: recommend_user['run'] = '全民健身动起来' recommend_user['avatar'] = user_info['avatar'] recommend_user['post_id'] = str(recommend_user['_id']) del recommend_user['_id'] del recommend_user['pic_num'] recommend_user['pic_list'] = [{'ori_pic':options.ipnet + pic,'thumb_pic':options.ipnet+options.post_thumb_save_path+'t'+pic[-17:]} for pic in recommend_user['pic_list']] if int(uid): recommend_user['has_follow'] = '已关注' if FollowModel().get_follow_status(uid,recommend_user['uid']) else '关注' else: recommend_user['has_follow'] = '关注' return recommend_user_list
def release_post(self,uid,pic_str,content,address,longitude,latitude): """发布朋友圈说说""" pic_list = [] if pic_str: for pic in pic_str.split(','): pic_path = pic[pic.index('/Uploads'):] pic_list.append(pic_path) pic_num = len(pic_list) post_id = PostModel().release_post(uid,pic_list,content,address,pic_num,longitude,latitude) return post_id
def share_post(self, post_id): post_info = PostModel().get_post_info(post_id) share_url = options.ipnet + '/RunCircle/index.html?uid=35&token=83adde48c7654c46ae1bbe73fdac93bd&cat=ios#/app/hudongxiangqing/' + str( post_id) token_pos = share_url.find('token') share_url = share_url[:token_pos] + share_url[token_pos + 39:] share_dict = { 'title': self.share_title, 'content': post_info['content'], 'image': options.ipnet + post_info['pic_list'][0], 'url': share_url } return share_dict
def get_user_post(self,uid,page,perpage): """获取用户的朋友圈""" post_list = PostModel().get_user_post(uid,page,perpage) current_time = PublicFunc.get_current_stamp() is_today = 1 # 默认是今天 for post in post_list: post['post_id'] = str(post['_id']) del post['_id'] if not PublicFunc.get_date_today() == PublicFunc.stamp_to_Ymd(post['time']):is_today = 0 post['is_today'] = is_today date_info = PublicFunc.get_date_info(post['time'],['day','month']) # post['pic_list'] = [{'ori_pic':options.ipnet + pic,'thumb_pic':options.ipnet+options.post_thumb_save_path+'t'+pic[-17:]} for pic in post['pic_list']] post['pic_list'] = [{'ori_pic':options.ipnet + pic,'thumb_pic':options.ipnet+pic} for pic in post['pic_list']] post['day'] = date_info['day'] post['month'] = date_info['month'] return post_list
def send_love(self,uid,post_id): result = PostLoveModel().send_love(uid,post_id) if result == 'send_love': PostModel().love_oper(uid,post_id) return True return False #已经发送过了
def judge_post_exist(self,post_id): """判断是否存在该帖子""" result = PostModel().get_post_num(post_id) return True if result else False