Пример #1
0
def test_add_columns(database):
    """Test that all keys can be added also for row withous keys."""
    pytest.importorskip('flask')

    session = Session('name')
    project = {
        'default_columns': ['bar'],
        'handle_query_function': handle_query
    }

    session.update('query', '', {'query': 'id=2'}, project)
    table = session.create_table(database, 'id', ['foo'])
    assert table.columns == ['bar']  # selected row doesn't have a foo key
    assert 'foo' in table.addcolumns  # ... but we can add it
Пример #2
0
def search(project_name: str):
    """Search page.

    Contains input form for database query and a table result rows.
    """
    session = Session(project_name)
    project = projects[project_name]
    return render_template(project['search_template'],
                           p=project,
                           session_id=session.id)
Пример #3
0
def search(project_name: str):
    """Search page.

    Contains input form for database query and a table result rows.
    """
    if project_name == 'favicon.ico':
        return '', 204, []  # 204: "No content"
    session = Session(project_name)
    project = projects[project_name]
    return render_template(project['search_template'],
                           q=request.args.get('query', ''),
                           p=project,
                           session_id=session.id)
Пример #4
0
def update(sid: int, what: str, x: str):
    """Update table of rows inside search page.

    ``what`` must be one of:

    * query: execute query in request.args (x not used)
    * limit: set number of rows to show to x
    * toggle: toggle column x
    * sort: sort after column x
    * page: show page x
    """
    session = Session.get(sid)
    project = projects[session.project_name]
    session.update(what, x, request.args, project)
    table = session.create_table(project['database'], project['uid_key'])
    return render_template('table.html', t=table, p=project, s=session)
Пример #5
0
def test_paging(database):
    """Test paging."""
    pytest.importorskip('flask')

    session = Session('name')
    project = {
        'default_columns': ['bar'],
        'handle_query_function': handle_query
    }

    session.update('query', '', {'query': ''}, project)
    table = session.create_table(database, 'id', ['foo'])
    assert len(table.rows) == 2

    session.update('limit', '1', {}, project)
    session.update('page', '1', {}, project)
    table = session.create_table(database, 'id', ['foo'])
    assert len(table.rows) == 1

    # We are now on page 2 and select something on page 1:
    session.update('query', '', {'query': 'id=1'}, project)
    table = session.create_table(database, 'id', ['foo'])
    assert len(table.rows) == 1