예제 #1
0
def test_paginator_bad_kwargs_fallback_data(monkeypatch, client):
    app, test = client
    monkeypatch.setattr(utils, 'setting', make_setting(0))
    monkeypatch.setattr(utils.adapter, 'count', make_count(0))
    # Ensure the paginator uses a minimum of 2 per page to prevent
    # division errors, even when there are no good values sent,
    # AND the app default setting is forcibly invalid (set to 0)
    paginator = utils.paginator(page=None, per_page=None, count=None)
    check_values(paginator, 2, 2, 0, 0, [], 0)
예제 #2
0
def test_paginator_bad_kwargs_fallback_data(monkeypatch, client):
    app, test = client
    monkeypatch.setattr(utils, 'setting', make_setting(0))
    monkeypatch.setattr(utils.adapter, 'count', make_count(0))
    # Ensure the paginator uses a minimum of 2 per page to prevent
    # division errors, even when there are no good values sent,
    # AND the app default setting is forcibly invalid (set to 0)
    paginator = utils.paginator(
        page=None, per_page=None, count=None)
    check_values(paginator, 2, 2, 0, 0, [], 0)
def dashboard():
    """Load all views."""
    opts = dict()
    views = []
    # Allow query parameter overrides.
    page = int(request.args.get('page', 0))
    per_page = int(request.args.get('per_page', setting('JSONDASH_PERPAGE')))
    if setting('JSONDASH_FILTERUSERS'):
        opts.update(filter=dict(created_by=metadata(key='username')))
        views = list(adapter.read(**opts))
        if setting('JSONDASH_GLOBALDASH'):
            opts.update(filter=dict(
                created_by=setting('JSONDASH_GLOBAL_USER')))
            views += list(adapter.read(**opts))
    else:
        views = list(adapter.read(**opts))
    if views:
        pagination = utils.paginator(count=len(views),
                                     page=page,
                                     per_page=per_page)
        opts.update(limit=pagination.limit, skip=pagination.skip)
        views = views[pagination.skip:pagination.next]
    else:
        pagination = None
    categorized = utils.categorize_views(views)
    kwargs = dict(
        total=len(views),
        views=categorized,
        view=None,
        paginator=pagination,
        creating=True,
        can_edit_global=auth(authtype='edit_global'),
        total_modules=sum([
            len(view.get('modules', [])) for view in views
            if isinstance(view, dict)
        ]),
    )
    return render_template('pages/charts_index.html', **kwargs)
예제 #4
0
def dashboard():
    """Load all views."""
    opts = dict()
    views = []
    # Allow query parameter overrides.
    page = int(request.args.get('page', 0))
    per_page = int(request.args.get(
        'per_page', setting('JSONDASH_PERPAGE')))
    if setting('JSONDASH_FILTERUSERS'):
        opts.update(filter=dict(created_by=metadata(key='username')))
        views = list(adapter.read(**opts))
        if setting('JSONDASH_GLOBALDASH'):
            opts.update(
                filter=dict(created_by=setting('JSONDASH_GLOBAL_USER')))
            views += list(adapter.read(**opts))
    else:
        views = list(adapter.read(**opts))
    if views:
        pagination = utils.paginator(count=len(views),
                                     page=page, per_page=per_page)
        opts.update(limit=pagination.limit, skip=pagination.skip)
        views = views[pagination.skip:pagination.next]
    else:
        pagination = None
    categorized = utils.categorize_views(views)
    kwargs = dict(
        total=len(views),
        views=categorized,
        view=None,
        paginator=pagination,
        creating=True,
        can_edit_global=auth(authtype='edit_global'),
        total_modules=sum([
            len(view.get('modules', [])) for view in views
            if isinstance(view, dict)
        ]),
    )
    return render_template('pages/charts_index.html', **kwargs)
예제 #5
0
def test_paginator_default_fallback_data_lt_2(monkeypatch, client):
    app, test = client
    monkeypatch.setattr(utils, 'setting', make_setting(0))
    monkeypatch.setattr(utils.adapter, 'count', make_count(0))
    paginator = utils.paginator(page=None, per_page=1, count=None)
    check_values(paginator, 2, 2, 0, 0, [], 0)
예제 #6
0
def test_paginator_norecords(monkeypatch, client):
    app, test = client
    monkeypatch.setattr(utils, 'setting', make_setting(30))
    monkeypatch.setattr(utils.adapter, 'count', make_count(0))
    paginator = utils.paginator(page=0)
    check_values(paginator, 30, 30, 0, 0, [], 0)
예제 #7
0
def test_paginator_default_usage(monkeypatch, client):
    app, test = client
    monkeypatch.setattr(utils, 'setting', make_setting(30))
    monkeypatch.setattr(utils.adapter, 'count', make_count(1000))
    paginator = utils.paginator(page=0)
    check_values(paginator, 30, 30, 0, 0, range(1, 35), 1000)
예제 #8
0
def test_paginator_default_fallback_data_lt_2(monkeypatch, client):
    app, test = client
    monkeypatch.setattr(utils, 'setting', make_setting(0))
    monkeypatch.setattr(utils.adapter, 'count', make_count(0))
    paginator = utils.paginator(page=None, per_page=1, count=None)
    check_values(paginator, 2, 2, 0, 0, [], 0)
예제 #9
0
def test_paginator_norecords(monkeypatch, client):
    app, test = client
    monkeypatch.setattr(utils, 'setting', make_setting(30))
    monkeypatch.setattr(utils.adapter, 'count', make_count(0))
    paginator = utils.paginator(page=0)
    check_values(paginator, 30, 30, 0, 0, [], 0)
예제 #10
0
def test_paginator_default_usage(monkeypatch, client):
    app, test = client
    monkeypatch.setattr(utils, 'setting', make_setting(30))
    monkeypatch.setattr(utils.adapter, 'count', make_count(1000))
    paginator = utils.paginator(page=0)
    check_values(paginator, 30, 30, 0, 0, range(1, 35), 1000)