Esempio n. 1
0
def api_findByName(simulation_type, application_mode, simulation_name):
    if cfg.oauth_login:
        from sirepo import oauth
        oauth.set_default_state(logged_out_as_anonymous=True)
    # use the existing named simulation, or copy it from the examples
    rows = simulation_db.iterate_simulation_datafiles(simulation_type, simulation_db.process_simulation_list, {
        'simulation.name': simulation_name,
        'simulation.isExample': True,
    })
    if len(rows) == 0:
        for s in simulation_db.examples(simulation_type):
            if s['models']['simulation']['name'] == simulation_name:
                simulation_db.save_new_example(s)
                rows = simulation_db.iterate_simulation_datafiles(simulation_type, simulation_db.process_simulation_list, {
                    'simulation.name': simulation_name,
                })
                break
        else:
            raise AssertionError(util.err(simulation_name, 'simulation not found with type {}', simulation_type))
    return javascript_redirect(
        uri_router.format_uri(
            simulation_type,
            application_mode,
            rows[0]['simulationId'],
            simulation_db.get_schema(simulation_type)
        )
    )
Esempio n. 2
0
def api_findByName(simulation_type, application_mode, simulation_name):
    if cfg.oauth_login:
        from sirepo import oauth
        oauth.set_default_state(logged_out_as_anonymous=True)
    redirect_uri = None
    # use the existing named simulation, or copy it from the examples
    rows = simulation_db.iterate_simulation_datafiles(simulation_type, simulation_db.process_simulation_list, {
        'simulation.name': simulation_name,
    })
    if len(rows) == 0:
        for s in simulation_db.examples(simulation_type):
            if s['models']['simulation']['name'] == simulation_name:
                simulation_db.save_new_example(simulation_type, s)
                rows = simulation_db.iterate_simulation_datafiles(simulation_type, simulation_db.process_simulation_list, {
                    'simulation.name': simulation_name,
                })
                break
    if len(rows):
        if application_mode == 'default':
            redirect_uri = '/{}#/source/{}'.format(simulation_type, rows[0]['simulationId'])
        elif application_mode == 'lattice':
            redirect_uri = '/{}#/lattice/{}'.format(simulation_type, rows[0]['simulationId'])
        elif application_mode == 'wavefront' or application_mode == 'light-sources':
            redirect_uri = '/{}#/beamline/{}?application_mode={}'.format(
                simulation_type, rows[0]['simulationId'], application_mode)
        else:
            redirect_uri = '/{}#/source/{}?application_mode={}'.format(
                simulation_type, rows[0]['simulationId'], application_mode)
    if redirect_uri:
        return javascript_redirect(redirect_uri)
    werkzeug.exceptions.abort(404)
Esempio n. 3
0
def api_root(simulation_type):
    try:
        sirepo.template.assert_sim_type(simulation_type)
    except AssertionError:
        pkdlog('{}: uri not found', simulation_type)
        werkzeug.exceptions.abort(404)
    if cfg.oauth_login:
        from sirepo import oauth
        values = oauth.set_default_state()
    else:
        values = pkcollections.Dict()
    values.app_name = simulation_type
    values.oauth_login = cfg.oauth_login
    return _render_root_page('index', values)