Пример #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)
        )
    )
Пример #2
0
def api_findByName(simulation_type, application_mode, simulation_name):
    # 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:
            util.raise_not_found('{}: simulation not found by name: {}', simulation_type, simulation_name)
    return javascript_redirect(
        uri_router.format_uri(
            simulation_type,
            application_mode,
            rows[0]['simulationId'],
            simulation_db.get_schema(simulation_type)
        )
    )