Beispiel #1
0
def default_run():
    """Retrieve the default run rumber from veloview.

    Used when no run number is specified by the user, or if the given run is
    invalid (as judged by valid_run`).
    """
    return runview_utils.run_list()[0]
def veloview_configuration(param):
    from veloview.core import run_view_config
    from veloview.runview import utils

    if param == "run_view_config":
        sys.stdout.write(json.dumps(run_view_config.run_view_pages))
    elif param == "run_list":
        sys.stdout.write("\n".join([str(r) for r in utils.run_list()]))
Beispiel #3
0
def run_view_builder(run, page, sensor):
    # See if the request was for a particular run/page/sensor and redirect
    # If any GET parameter wasn't specified, or was specified with an invalid
    # value, fall back to the default
    if request.args:
        run = request.args.get('run', run)
        page = request.args.get('page', page)
        sensor = request.args.get('sensor', sensor)
        # Check that the integer URL params are castable
        try:
            run = int(run)
        except ValueError:
            new_run = default_run()
            flash('Invalid run number "{0}", reset to "{1}"'.format(
                run, new_run
            ), 'error')
            run = new_run
        try:
            sensor = int(sensor)
        except ValueError:
            new_sensor = 0
            flash('Invalid sensor number "{0}", reset to "{1}"'.format(
                sensor, new_sensor
            ), 'error')
            sensor = new_sensor
        url = url_for('run_view.run_view_builder',
                      run=run,
                      page=page,
                      sensor=sensor)
        return redirect(url)

    # Check if the run number is valid, redirecting to default if not
    if not runview_utils.valid_run(run):
        new_run = default_run()
        flash('Invalid run number "{0}", reset to "{1}"'.format(run, new_run),
              'error')
        run = new_run
        url = url_for('run_view.run_view_builder',
                      run=run,
                      page=page,
                      sensor=sensor)
        return redirect(url)

    # Check if the sensor number is valid, redirecting to default (0) if not
    if not runview_utils.valid_sensor(sensor):
        flash('Invalid sensor number "{0}", reset to "0"'.format(sensor),
              'error')
        sensor = 0
        url = url_for('run_view.run_view_builder',
                      run=run,
                      page=page,
                      sensor=sensor)
        return redirect(url)

    # Load the default page from the configuration if we're at the root
    if page == '':
        page = current_app.config['DEFAULT_CHILDREN'].get('run_view', None)
        if page is not None:
            page = page[len('run_view/'):]
    # Else load the page data associated with the route's page
    page_data = run_view_config.run_view_pages.get(page, None)

    # Set up the required template variables and render the page
    g.page = page
    g.pages = run_view_config.run_view_pages
    g.page_data = page_data
    g.run = run
    g.runs = runview_utils.run_list()
    g.nearby_runs = nearby_runs(g.run, g.runs)
    g.sensor = sensor
    g.active_page = 'run_view/{0}'.format(page)

    # 404 if the page doesn't exist in the config dict
    if page_data is None:
        abort(404)

    return render_template('run_view/dynamic.html')
 def test_run_list(self):
     """Should return a list of high-low sorted run numbers as integers."""
     self.assertEqual(utils.run_list(), sorted(RUNS, reverse=True))