예제 #1
0
def test_parse_request(app):
    with app.test_request_context(
            '/healthz/?page=3&per_page=40&order_by=test&order_dir=up'):
        Query.parse_request(request)
        assert g.page == '3'
        assert g.per_page == '40'
        assert g.order_by == 'test'
        assert g.order_dir == 'up'
예제 #2
0
 def add_pagination(self, data):
     page = int(Query.get_param('page'))
     per_page = Query.get_param('per_page')
     if page > 1:
         data[
             "prev"] = request.base_url + f'?page={page - 1}&per_page={per_page}'
     data[
         "next"] = request.base_url + f'?page={page + 1}&per_page={per_page}'
     data[
         "current"] = request.base_url + f'?page={page}&per_page={per_page}'
예제 #3
0
def query_score(loginService):
    data = {'code': 0, 'msg': '查询成功!', 'data': {}}
    query = Query(loginService)
    grade = int(request.values.get('Grade', 0))
    term = int(request.values.get('term', 0))
    data['data'] = query.query_score_a_term({'Grade': grade, 'term': term})
    from app.models.entry.score import Score
    data['data']['others'] = Score.calculate_all(data['data'])
    loginService.logout()
    return JsonpFormat.callback(data)
예제 #4
0
def query_schedule(loginService):
    data = {'code': 0, 'msg': '查询成功!', 'data': {}}
    query = Query(loginService)
    grade = int(request.values.get('Grade', 0))
    term = int(request.values.get('term', 0))
    condition = None
    if grade > 0 and term > 0:
        condition = {'Grade': grade, 'term': term}
    data['data'] = query.query_schedule_a_term(condition)
    loginService.logout()
    return JsonpFormat.callback(data)
예제 #5
0
    def test_query(self):
        from app.models.entry.student import Student
        d = '用户账号\n用户密码'
        import base64
        b_d = base64.b64encode(d.encode())
        stu = Student(b_d.decode())

        loginService = LoginService()
        if loginService.login_user(stu):
            q = Query(loginService)
            ls = q.query_schedule_a_term()
            print(ls)
예제 #6
0
 def get_all(cls):
     """
     Returns all the items paginated. The `page`, `per_page`, and `max_per_page`
     are gotten from Flask scope.
     """
     query = cls.model.query
     order_by = Query.get_param('order_by')
     order_dir = Query.get_param('order_dir')
     table_name = cls.model.__tablename__
     columns = [
         column.name
         for column in cls.model.metadata.tables[table_name].columns
     ]
     if order_by is not None and order_by in columns:
         if order_dir == 'desc':
             query = query.order_by(getattr(cls.model, order_by).desc())
         else:
             query = query.order_by(getattr(cls.model, order_by).asc())
     return query.paginate(
         page=Query.get_param('page'),
         per_page=Query.get_param('per_page'),
         error_out=False,
         max_per_page=Query.get_param('max_per_page')).items
예제 #7
0
 def decorated_function(*args, **kwargs):
     Query.parse_request(request)
     return f(*args, **kwargs)