コード例 #1
0
def display_page(pathname, search):
    """
    Returns the page content to be displayed depending on pathname and search.

    :param pathname: current pathname
    :param search: current search
    :returns: page content layout (html.Div children possibility)
    """
    if pathname == '/login':
        return login.layout
    elif not auth.is_authorized():
        return auth.login_page_redirect
    elif pathname == '/':
        return parse_search(status.layout, search, 'week', status_week.layout)
    elif pathname == '/vms':
        return parse_search(vms.layout, search, 'vm', vms_vm.layout)
    elif pathname == '/history':
        return history.layout
    elif pathname == '/account':
        return account.layout
    elif pathname == '/logout':
        return logout.layout
    else:
        # TODO: Implement 404 page
        raise PreventUpdate
コード例 #2
0
def set_username(_):
    """
    Sets the session's username in the right column.

    :returns: the current username (string)
    """
    if auth.is_authorized():
        return auth.get_username()
コード例 #3
0
def toggle_schedule_button(_, __, ___):
    """
    Toggles the test scheduling button's visibility depending on whether user
    is logged in and an admin.

    :returns: html style
    """
    if auth.is_authorized() and auth.is_admin():
        return {}
    else:
        return {'display': 'none'}
コード例 #4
0
def toggle_next_test(_, __, ___):
    """
    Toggles the next test's button visibility depending on whether user is
    logged in.

    :returns: html style
    """
    if auth.is_authorized():
        return {}
    else:
        return {'display': 'none'}
コード例 #5
0
def insert_next_test(_, __, ___, date):
    """
    Inserts the text for the button displaying the time of the next scheduled
    test.

    :param date: if tests have been scheduled since date, show update available
    :returns: time until next test schedule or update available (string)
    """
    if not auth.is_authorized():
        return
    if date is not None and scheduled_test_ran_since(date):
        return "update available"
    return "next " + formatted_next_tests_scheduled()
コード例 #6
0
def insert_schedule_tests_button(n):
    """
    Inserts the button for scheduling a new test and inserts test scheduling
    when button is clicked.

    :param n: number of clicks of button
    :returns: html.Button if authorized, None otherwise
    """
    # Catch non authorized requests
    if not auth.is_authorized() or not auth.is_admin():
        return
    # None means page load
    if n is None:
        return html.Button('Schedule now', className='topbar-button')
    # n=1 means first click on button
    if n == 1:
        by = auth.get_username()
        add_test_scheduling(by)
        return html.Button('Scheduled', className='topbar-button')