def get(self): parser = reqparse.RequestParser() parser.add_argument('TOKEN', type=str, location='headers') args = parser.parse_args() user = User.verify_auth_token(args['TOKEN']) if not user: return Results().get(ResponseCode.FAIL_LOGIN_AUTH) results = TestSheet.get_or_none(TestSheet.qa_id == user.id, TestSheet.status == '待部署') if results is None: return Results().get(ResponseCode.SUCCESS) result_data = Results().set_data() results = TestSheet.select().where(TestSheet.qa_id == user.id, TestSheet.status == '待部署').order_by( TestSheet.create_time.desc()) for result in results: testsheet_data = convert_json(TestSheet, result.id) ResponseStructure().set_username(data=testsheet_data, id=testsheet_data['qa_id'], user='******') ResponseStructure().set_username(data=testsheet_data, id=testsheet_data['backend_id'], user='******') ResponseStructure().set_username(data=testsheet_data, id=testsheet_data['front_id'], user='******') result_data.append(testsheet_data) return Results().get(ResponseCode.SUCCESS, data=result_data)
def get(self): parser = reqparse.RequestParser() parser.add_argument('title', type=str, default='') parser.add_argument('name', type=str, default='') parser.add_argument('page', type=int, default=1) parser.add_argument('per_page', type=int, default=10) parser.add_argument('TOKEN', location='headers', type=str) args = parser.parse_args() user = User.verify_auth_token(args['TOKEN']) if not user: return Results().get(ResponseCode.FAIL_LOGIN_AUTH) pageNo = verify_negative_number(args['page'], 1) per_page = verify_negative_number(args['per_page'], 10) user_id = verify_user(args['name']) result_data = Results().set_data() total_count = 0 if user_id is None and (args['title'] == '' or args['title'] is None): for t in TestSheet.select().order_by( TestSheet.create_time.desc()).paginate(pageNo, per_page): testsheet_data = convert_json(TestSheet, t.id) ResponseStructure().set_username(data=testsheet_data, id=testsheet_data['qa_id'], user='******') ResponseStructure().set_username( data=testsheet_data, id=testsheet_data['backend_id'], user='******') ResponseStructure().set_username(data=testsheet_data, id=testsheet_data['front_id'], user='******') result_data.append(testsheet_data) total_count = TestSheet.select().count() if user_id and args['title']: for t in TestSheet.select().join(User).where( TestSheet.title % '%{}%'.format(args['title']), User.id == user_id).order_by( TestSheet.create_time.desc()).paginate( pageNo, per_page): testsheet_data = convert_json(TestSheet, t.id) ResponseStructure().set_username(data=testsheet_data, id=testsheet_data['qa_id'], user='******') ResponseStructure().set_username( data=testsheet_data, id=testsheet_data['backend_id'], user='******') ResponseStructure().set_username(data=testsheet_data, id=testsheet_data['front_id'], user='******') result_data.append(testsheet_data) total_count = TestSheet.select().join(User).where( TestSheet.title % '%{}%'.format(args['title']), User.username == args['name']).count() if args['title'] and not args['name']: for t in TestSheet.select().where( TestSheet.title % '%{}%'.format(args['title'])).order_by( TestSheet.create_time.desc()).paginate( pageNo, per_page): testsheet_data = convert_json(TestSheet, t.id) ResponseStructure().set_username(data=testsheet_data, id=testsheet_data['qa_id'], user='******') ResponseStructure().set_username( data=testsheet_data, id=testsheet_data['backend_id'], user='******') ResponseStructure().set_username(data=testsheet_data, id=testsheet_data['front_id'], user='******') result_data.append(testsheet_data) total_count = TestSheet.select().where(TestSheet.title % args['title']).count() if user_id and not args['title']: for t in TestSheet.select().where( (TestSheet.qa_id == user_id) | (TestSheet.backend_id == user_id) | (TestSheet.front_id == user_id)).order_by( TestSheet.create_time.desc()).paginate( pageNo, per_page): testsheet_data = convert_json(TestSheet, t.id) ResponseStructure().set_username(data=testsheet_data, id=testsheet_data['qa_id'], user='******') ResponseStructure().set_username( data=testsheet_data, id=testsheet_data['backend_id'], user='******') ResponseStructure().set_username(data=testsheet_data, id=testsheet_data['front_id'], user='******') result_data.append(testsheet_data) total_count = TestSheet.select().where( (TestSheet.qa_id == user_id) | (TestSheet.backend_id == user_id) | (TestSheet.front_id == user_id)).count() total_page_count = Page().get_total_page_count(total_count, per_page) is_has_next_page, is_has_previous_page = Page( ).verify_previous_page_and_next_page(pageNo, total_page_count) page_result = Page().pagination(currentPageNo=args['page'], hasNextPage=is_has_next_page, hasPreviousPage=is_has_previous_page, totalCount=total_count, totalPageCount=total_page_count) return Results().get(ResponseCode.SUCCESS_GET_TESTSHEET, data=result_data, page_result=page_result)