def list_request_answer(): user_request_id = request.args.get("user_request_id") user_ID = request.args.get("user_ID") page_no = int(request.args.get("page_no", 1)) page_size = int(request.args.get("page_size", 10)) type = request.args.get("type") search_query = request.args.get("search_query") if user_request_id: request_answer = request_answer_service. \ get_all_answer_of_this_user_request(user_request_id) for each_one in request_answer: # todo 删除历史数据后,可删除此判断 if each_one.answer_user: each_one.answer_user_ID = each_one.answer_user.user_ID request_answer_info = json_utility. \ me_obj_list_to_json_list(request_answer) # 得到每一个answer下的comments 和 selcet project for index, answer in enumerate(request_answer_info): answer_comment = comments_service.get_comments_of_this_answer( answer['_id']) answer_comment_info = json_utility. \ me_obj_list_to_json_list(answer_comment) answer['comment'] = answer_comment_info if 'select_project' in answer: # 获取commit try: commits = ProjectBusiness.get_commits( request_answer[index].select_project.path) select_project = request_answer[index].select_project select_project.commits = [{ 'message': c.message, 'time': datetime.fromtimestamp(c.time[0] + c.time[1]), } for c in commits] answer['select_project'] = json_utility.convert_to_json( select_project.to_mongo()) except: print('selected app has been deleted') answer['select_project'] = {'deleted': True} return jsonify({'response': request_answer_info}), 200 elif user_ID: request_answer, total_number = request_answer_service. \ get_all_answer_by_user_ID(user_ID, page_no, page_size, type, search_query) request_answer_info = json_utility. \ me_obj_list_to_json_list(request_answer) return jsonify({ 'response': { 'request_answer_info': request_answer_info, 'total_number': total_number } }), 200 else: return jsonify({'response': 'insufficient arguments'}), 400
def get_project(project_id): if not project_id: return jsonify({'response': 'no project_id arg'}), 400 project = ProjectBusiness.get_by_id(project_id) if request.args.get('commits') == 'true': commits = ProjectBusiness.get_commits(project.path) project.commits = [{ 'message': c.message, 'time': datetime.fromtimestamp(c.time[0] + c.time[1]), } for c in commits] project = json_utility.convert_to_json(project.to_mongo()) return make_response(jsonify({'response': project}), 200)