Ejemplo n.º 1
0
def scrub():
    # Are you looking for scrubber.py?
    """Handles the functionality of the scrub page.

    It scrubs the files depending on the specifications chosen by the user,
    with an option to download the scrubbed files.
    :return: a response object (often a render_template call) to flask and
     eventually to the browser.
    """
    # Detect the number of active documents.
    num_active_docs = detect_active_docs()
    file_manager = utility.load_file_manager()

    # "GET" request occurs when the page is first loaded.
    if 'scrubbingoptions' not in session:
        session['scrubbingoptions'] = constants.DEFAULT_SCRUB_OPTIONS
    if 'xmlhandlingoptions' not in session:
        session['xmlhandlingoptions'] = {
            "myselect": {"action": '', "attribute": ""}}
    utility.xml_handling_options()
    previews = file_manager.get_previews_of_active()
    tags_present, doe_present, gutenberg_present = \
        file_manager.check_actives_tags()
    return render_template(
        'scrub.html',
        previews=previews,
        itm="scrubber",
        haveTags=tags_present,
        haveDOE=doe_present,
        haveGutenberg=gutenberg_present,
        numActiveDocs=num_active_docs)
Ejemplo n.º 2
0
def scrub():
    # Are you looking for scrubber.py?
    """Handles the functionality of the scrub page.

    It scrubs the files depending on the specifications chosen by the user,
    with an option to download the scrubbed files.
    :return: a response object (often a render_template call) to flask and
     eventually to the browser.
    """
    # Detect the number of active documents.
    num_active_docs = detect_active_docs()
    file_manager = utility.load_file_manager()

    # "GET" request occurs when the page is first loaded.
    if 'scrubbingoptions' not in session:
        session['scrubbingoptions'] = constants.DEFAULT_SCRUB_OPTIONS
    if 'xmlhandlingoptions' not in session:
        session['xmlhandlingoptions'] = {
            "myselect": {
                "action": '',
                "attribute": ""
            }
        }
    utility.xml_handling_options()
    previews = file_manager.get_previews_of_active()
    tags_present, doe_present, gutenberg_present = \
        file_manager.check_actives_tags()
    return render_template('scrub.html',
                           previews=previews,
                           itm="scrubber",
                           haveTags=tags_present,
                           haveDOE=doe_present,
                           haveGutenberg=gutenberg_present,
                           numActiveDocs=num_active_docs)
Ejemplo n.º 3
0
def xml() -> str:
    """ Sets the tag options.
    :return: None.
    """

    data = request.json
    utility.xml_handling_options(data)
    return ""
Ejemplo n.º 4
0
def xml():
    """Handle XML tags.

    :return: string indicating that it has succeeded
    """
    data = request.json
    utility.xml_handling_options(data)
    return "success"
Ejemplo n.º 5
0
def xml():
    """Handle XML tags.

    :return: string indicating that it has succeeded
    """
    data = request.json
    utility.xml_handling_options(data)
    return "success"
Ejemplo n.º 6
0
def set_all_tags_table():
    """sets all the tags options.

    :return: json object with the result html
    """
    data = request.json
    utility.xml_handling_options()
    s = ''
    data = data.split(',')
    keys = sorted(session['xmlhandlingoptions'].keys())

    for key in keys:
        b = '<select name="' + key + '">'
        if data[0] == 'remove-element':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '" selected="selected">' \
                 'Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element\'s Contents with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        elif data[0] == 'replace-element':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '" selected="selected">' \
                 'Replace Element\'s Contents with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        elif data[0] == 'leave-alone':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element\'s Contents with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '" selected="selected">Leave Tag Alone</option>'
        else:
            b += '<option value="remove-tag,' + key + \
                 '" selected="selected">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element\'s Contents with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        b += '</select>'
        c = 'Attribute: <input type="text" name="attributeValue' + key + \
            '"  value="' + session['xmlhandlingoptions'][key]["attribute"] + \
            '"/>'
        s += "<tr><td>" + key + "</td><td>" + b + "</td><td>" + c + \
             "</td></tr>"
    return json.dumps(s)
Ejemplo n.º 7
0
def set_all_tags_table():
    """sets all the tags options.

    :return: json object with the result html
    """
    data = request.json
    utility.xml_handling_options()
    s = ''
    data = data.split(',')
    keys = sorted(session['xmlhandlingoptions'].keys())

    for key in keys:
        b = '<select name="' + key + '">'
        if data[0] == 'remove-element':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '" selected="selected">' \
                 'Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element\'s Contents with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        elif data[0] == 'replace-element':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '" selected="selected">' \
                 'Replace Element\'s Contents with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        elif data[0] == 'leave-alone':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element\'s Contents with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '" selected="selected">Leave Tag Alone</option>'
        else:
            b += '<option value="remove-tag,' + key + \
                 '" selected="selected">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element\'s Contents with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        b += '</select>'
        c = 'Attribute: <input type="text" name="attributeValue' + key + \
            '"  value="' + session['xmlhandlingoptions'][key]["attribute"] + \
            '"/>'
        s += "<tr><td>" + key + "</td><td>" + b + "</td><td>" + c + \
             "</td></tr>"
    return json.dumps(s)
Ejemplo n.º 8
0
def get_tags_table() -> str:
    """ Gets the tags in the active documents.
    :return: The tags in the active documents.
    """

    utility.xml_handling_options()
    tags = humansorted(list(session["xmlhandlingoptions"].keys()))

    response = []
    for tag in tags:
        response.append([
            tag, session["xmlhandlingoptions"][tag]["action"],
            session["xmlhandlingoptions"][tag]["attribute"]
        ])

    return json.dumps(response)
Ejemplo n.º 9
0
def scrub() -> str:
    """ Gets the scrub page.
    :return: The scrub page.
    """

    if "scrubbingoptions" not in session:
        session["scrubbingoptions"] = constants.DEFAULT_SCRUB_OPTIONS
    if "xmlhandlingoptions" not in session:
        session["xmlhandlingoptions"] = {
            "myselect": {
                "action": "",
                "attribute": ""
            }
        }
    utility.xml_handling_options()

    return render("scrub.html")
Ejemplo n.º 10
0
def get_tags_table():
    """ :return: an html table of the xml handling options
    """
    from natsort import humansorted
    utility.xml_handling_options()
    s = ''
    keys = list(session['xmlhandlingoptions'].keys())
    keys = humansorted(keys)
    for key in keys:
        b = '<select name="' + key + '">'
        if session['xmlhandlingoptions'][key]['action'] == r'remove-element':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '" selected="selected">' \
                 'Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element and Its Contents with Attribute Value' \
                 '</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        elif session['xmlhandlingoptions'][key]["action"] == 'replace-element':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '" selected="selected">Replace Element and Its ' \
                 'Contents with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        elif session['xmlhandlingoptions'][key]["action"] == r'leave-alone':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element and Its Contents ' \
                 'with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '" selected="selected">Leave Tag Alone</option>'
        else:
            b += '<option value="remove-tag,' + key + \
                 '" selected="selected">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element and Its Contents with Attribute Value' \
                 '</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        b += '</select>'
        c = 'Attribute: <input type="text" name="attributeValue' + key + \
            '"  value="' + session['xmlhandlingoptions'][key]["attribute"] + \
            '"/>'
        s += "<tr><td>" + key + "</td><td>" + b + "</td><td>" + c + \
             "</td></tr>"

    response = {"menu": s, "selected-options": "multiple"}

    # Count the number of actions and change selected-options to
    # the selected option if they are all the same.
    num_actions = []
    for item in session['xmlhandlingoptions'].items():
        num_actions.append(item[1]["action"])
    num_actions = list(set(num_actions))
    if len(num_actions) == 1:
        response["selected-options"] = num_actions[0] + ",allTags"

    return json.dumps(response)
Ejemplo n.º 11
0
def get_tags_table():
    """ :return: an html table of the xml handling options
    """
    from natsort import humansorted
    utility.xml_handling_options()
    s = ''
    keys = list(session['xmlhandlingoptions'].keys())
    keys = humansorted(keys)
    for key in keys:
        b = '<select name="' + key + '">'
        if session['xmlhandlingoptions'][key]['action'] == r'remove-element':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '" selected="selected">' \
                 'Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element and Its Contents with Attribute Value' \
                 '</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        elif session['xmlhandlingoptions'][key]["action"] == 'replace-element':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '" selected="selected">Replace Element and Its ' \
                 'Contents with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        elif session['xmlhandlingoptions'][key]["action"] == r'leave-alone':
            b += '<option value="remove-tag,' + key + \
                 '">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element and Its Contents ' \
                 'with Attribute Value</option>'
            b += '<option value="leave-alone,' + key + \
                 '" selected="selected">Leave Tag Alone</option>'
        else:
            b += '<option value="remove-tag,' + key + \
                 '" selected="selected">Remove Tag Only</option>'
            b += '<option value="remove-element,' + key + \
                 '">Remove Element and All Its Contents</option>'
            b += '<option value="replace-element,' + key + \
                 '">Replace Element and Its Contents with Attribute Value' \
                 '</option>'
            b += '<option value="leave-alone,' + key + \
                 '">Leave Tag Alone</option>'
        b += '</select>'
        c = 'Attribute: <input type="text" name="attributeValue' + key + \
            '"  value="' + session['xmlhandlingoptions'][key]["attribute"] + \
            '"/>'
        s += "<tr><td>" + key + "</td><td>" + b + "</td><td>" + c + \
             "</td></tr>"

    response = {"menu": s, "selected-options": "multiple"}

    # Count the number of actions and change selected-options to
    # the selected option if they are all the same.
    num_actions = []
    for item in session['xmlhandlingoptions'].items():
        num_actions.append(item[1]["action"])
    num_actions = list(set(num_actions))
    if len(num_actions) == 1:
        response["selected-options"] = num_actions[0] + ",allTags"

    return json.dumps(response)