def detach_node(scenario_id):
    """Detach scenario node from the structure tree."""
    scenario_manager = ScenarioManager(get_autostorage_api())
    single_scenario_manager = scenario_manager.get_scenario(scenario_id)

    tree_path = request.args.get('tree_path')

    single_scenario_manager.detach_node(tree_path=tree_path)

    return redirect(url_for('single_scenario', scenario_id=scenario_id))
def attach_node(scenario_id):
    """Attach scenario node to the structure tree."""
    scenario_manager = ScenarioManager(get_autostorage_api())
    single_scenario_manager = scenario_manager.get_scenario(scenario_id)

    parent_tree_path = request.args.get('parent_tree_path')
    node_id = int(request.args.get('node_id'))

    single_scenario_manager.attach_node(node_ids=[node_id], parent_tree_path=parent_tree_path)

    return redirect(url_for('single_scenario', scenario_id=scenario_id))
def single_scenario(scenario_id):
    """Return page for single scenario."""
    api = get_autostorage_api()
    scenario_manager = ScenarioManager(api)
    single_scenario_manager = scenario_manager.get_scenario(scenario_id)
    with api.get_session() as session:
        view_states = single_scenario_manager.get_view_states().with_session(session).all()

    current_view_state = view_states[0]
    current_name = current_view_state.name
    current_description = current_view_state.description

    name_form = EditScenarioNameForm(original_name=current_name)
    description_form = EditScenarioDescriptionForm(original_description=current_description)

    if name_form.rename.data and name_form.validate_on_submit():
        single_scenario_manager.rename(name_form.name.data)

        flash('Your changes have been saved.')
        return redirect(url_for('single_scenario', scenario_id=scenario_id))
    else:
        name_form.name.data = current_name

    if description_form.change_description.data and description_form.validate_on_submit():
        single_scenario_manager.change_description(description_form.description.data)

        flash('Your changes have been saved.')
        return redirect(url_for('single_scenario', scenario_id=scenario_id))
    else:
        description_form.description.data = current_description

    structure_tree = _create_tree(single_scenario_manager)

    node_manager = ScenarioNodeManager(api)
    with api.get_session() as session:
        node_states = node_manager.get_scenario_node_states().with_session(session).all()

    return render_template(
        "single_scenario.html",
        scenario_id=scenario_id,
        scenario_name=current_name,
        scenario_description=current_description,
        view_states=view_states,
        name_form=name_form,
        description_form=description_form,
        structure_tree=structure_tree,
        node_states=node_states
        )
示例#4
0
def scenarios():
    """Return page with scenarios."""
    new_scenario_form = CreateScenarioForm()
    api = get_autostorage_api()
    scenario_manager = ScenarioManager(api)
    if new_scenario_form.validate_on_submit():
        single_scenario_manager = scenario_manager.create_scenario(new_scenario_form.name.data)
        single_scenario_manager.change_description(new_scenario_form.description.data)

    with api.get_session() as session:
        view_states = scenario_manager.get_scenarios_view_states().with_session(session).all()

    return render_template(
        "scenarios.html",
        view_states=view_states,
        new_scenario_form=new_scenario_form,
        )