コード例 #1
0
def graphic_config_setup():
    graphic_status = request.form[GRAPHIC_STATUS]

    config_dict = load_main_config_dict_if_exists(current_app)
    copy_data_from_form_to_config(config_dict, request.form)
    save_main_config_dict(config_dict)
    active_data_source_names = None
    collapse_dict = get_default_collapse_dict()
    if graphic_status in [COPY, OLD]:
        graphic_dict = json.loads(
            load_graphic_config_dict(request.form[GRAPHIC]))
        active_data_source_names = extract_data_sources_from_config(
            graphic_dict)
        collapse_dict = generate_collapse_dict_from_graphic_component_dict(
            graphic_dict)

    (
        data_source_names,
        possible_column_names,
        unique_entries_dict,
    ) = get_data_source_info(active_data_source_names)
    # concatenating into one large list with no duplicates
    unique_entries_list = list(
        set(itertools.chain.from_iterable(unique_entries_dict.values())))
    graphic_schemas, schema_to_type = build_graphic_schemas_for_ui(
        data_source_names, possible_column_names, unique_entries_list,
        collapse_dict)
    component_graphic_dict = make_empty_component_dict()
    current_schema = SCATTER

    if graphic_status in [COPY, OLD]:
        type_to_schema = invert_dict_lists(schema_to_type)
        current_schema = type_to_schema[graphic_dict[PLOT_SPECIFIC_INFO][DATA]
                                        [0].get(TYPE, SCATTER)]
        component_graphic_dict = graphic_dict_to_graphic_component_dict(
            graphic_dict)

    return render_template(
        GRAPHIC_CONFIG_EDITOR_HTML,
        schema=json.dumps(
            graphic_schemas,
            indent=4,
        ),
        page_id=request.form[PAGE_ID],
        current_config=json.dumps(component_graphic_dict),
        graphic_status=graphic_status,
        schema_selector_dict=json.dumps(SELECTOR_DICT),
        current_schema=current_schema,
        graphic_path=request.form[GRAPHIC],
        default_entries_dict=json.dumps(unique_entries_dict),
    )
コード例 #2
0
ファイル: wizard_view.py プロジェクト: syedpeer/Escalation
def update_graphic_json_config_with_ui_changes():
    config_information_dict = request.get_json()
    page_id = config_information_dict[PAGE_ID]
    graphic_dict = graphic_component_dict_to_graphic_dict(
        config_information_dict[CONFIG_DICT])
    graphic_filename = config_information_dict[GRAPHIC_PATH]
    # sanitizing the string so it is valid filename
    if config_information_dict[GRAPHIC_STATUS] in [NEW, COPY]:
        # Given a graphic title from the user input, make a valid json filename
        graphic_filename_no_ext = sanitize_string(graphic_dict[GRAPHIC_TITLE])
        if os.path.exists(
                os.path.join(
                    current_app.config[CONFIG_FILE_FOLDER],
                    f"{graphic_filename_no_ext}.json",
                )):
            i = 0
            while os.path.exists(
                    os.path.join(
                        current_app.config[CONFIG_FILE_FOLDER],
                        f"{graphic_filename_no_ext}_{i}.json",
                    )):
                i += 1
            graphic_filename = f"{graphic_filename_no_ext}_{i}.json"
        else:
            graphic_filename = f"{graphic_filename_no_ext}.json"
        # make sure we are not overwriting something
        main_config_dict = load_main_config_dict_if_exists(current_app)
        page_dict = main_config_dict[AVAILABLE_PAGES][page_id]
        graphic_list = page_dict.get(GRAPHIC_CONFIG_FILES, [])
        graphic_list.append(graphic_filename)
        page_dict[GRAPHIC_CONFIG_FILES] = graphic_list
        save_main_config_dict(main_config_dict)

    graphic_filepath = os.path.join(current_app.config[CONFIG_FILE_FOLDER],
                                    graphic_filename)
    # remove and write new file to trigger file watcher and refresh flask app
    if os.path.exists(graphic_filepath):
        os.remove(graphic_filepath)
    with open(graphic_filepath, "w") as fout:
        json.dump(graphic_dict, fout, indent=4)
    return (
        json.dumps({
            "success": True,
            GRAPHIC_PATH: graphic_filename
        }),
        200,
        {
            "ContentType": "application/json"
        },
    )
コード例 #3
0
ファイル: wizard_view.py プロジェクト: syedpeer/Escalation
def modify_layout():
    """
    Add a page
    Delete a page
    Delete a graphic from a page
    :return:
    """
    MODIFICATION = "modification"
    ADD_PAGE = "add_page"
    DELETE_PAGE = "delete_page"
    RENAME_PAGE = "rename_page"
    DELETE_GRAPHIC = "delete_graphic"

    config_dict = load_main_config_dict_if_exists(current_app)
    copy_data_from_form_to_config(config_dict, request.form)
    available_pages = config_dict.get(AVAILABLE_PAGES, [])
    modification = request.form[MODIFICATION]
    webpage_label = request.form[WEBPAGE_LABEL]
    page_id = int(request.form[PAGE_ID])
    if modification == ADD_PAGE:
        page_urls = [page_dict[URL_ENDPOINT] for page_dict in available_pages]
        page_dict = make_page_dict_for_main_config(webpage_label, page_urls)
        available_pages.append(page_dict)
    elif modification == RENAME_PAGE:
        page_urls = [page_dict[URL_ENDPOINT] for page_dict in available_pages]
        page_urls.pop(page_id)
        page_dict = make_page_dict_for_main_config(webpage_label, page_urls)
        page_dict[GRAPHIC_CONFIG_FILES] = available_pages[page_id].get(
            GRAPHIC_CONFIG_FILES, [])
        available_pages[page_id] = page_dict
    elif modification == DELETE_PAGE:
        del available_pages[page_id]
        # todo: iterate and delete actual json configs? But add confirmation?
    elif modification == DELETE_GRAPHIC:
        graphic_filename = request.form[GRAPHIC]
        graphic_filepath = os.path.join(current_app.config[CONFIG_FILE_FOLDER],
                                        graphic_filename)
        # remove and write new file to trigger file watcher and refresh flask app
        if os.path.exists(graphic_filepath):
            os.remove(graphic_filepath)
        available_pages[page_id][GRAPHIC_CONFIG_FILES].remove(graphic_filename)

    config_dict[AVAILABLE_PAGES] = available_pages
    save_main_config_dict(config_dict)
    return file_tree()
コード例 #4
0
ファイル: wizard_view.py プロジェクト: syedpeer/Escalation
def update_main_json_config_with_ui_changes():
    config_dict = request.get_json()
    save_main_config_dict(config_dict)
    return json.dumps({"success": True}), 200, {
        "ContentType": "application/json"
    }