Example #1
0
File: uci.py Project: jtojnar/foris
def create_post(node):
    operation = request.GET.get("operation")
    uci_model = client.get_uci_config()
    parent = uci_model.find_child(node)
    if isinstance(parent, uci_raw.Section):
        if operation == "add-list":
            form = UciRawForm(uci_raw.List, editable_key=True)
            if form.validates(request.POST):
                new_element = form.to_model()
        elif operation == "add-option":
            form = UciRawForm(uci_raw.Option, editable_key=True)
            if form.validates(request.POST):
                new_element = form.to_model()
        else:
            raise ValueError("Requested operation not allowed for Section node.")
    elif isinstance(parent, uci_raw.Config):
        form = UciRawForm(uci_raw.Section, editable_key=True)(request.POST)
        if form.validates(request.POST):
            new_element = form.to_model()
    elif isinstance(parent, uci_raw.List):
        form = UciRawForm(uci_raw.Value, editable_key=True)(request.POST)
        if form.validates(request.POST):
            new_element = form.to_model()
    else:
        raise ValueError("New node cannot be created here.")

    if not form.valid:
        return dict(node_path=node, form=form)

    new_element.operation = "create"
    parent.add(new_element)
    print_model(new_element)
    edit_uci_config(new_element)
    bottle.redirect(reverse("uci_index"))
Example #2
0
def create_post(node):
    operation = request.GET.get("operation")
    uci_model = client.get_uci_config()
    parent = uci_model.find_child(node)
    if isinstance(parent, uci_raw.Section):
        if operation == "add-list":
            form = UciRawForm(uci_raw.List, editable_key=True)
            if form.validates(request.POST):
                new_element = form.to_model()
        elif operation == "add-option":
            form = UciRawForm(uci_raw.Option, editable_key=True)
            if form.validates(request.POST):
                new_element = form.to_model()
        else:
            raise ValueError(
                "Requested operation not allowed for Section node.")
    elif isinstance(parent, uci_raw.Config):
        form = UciRawForm(uci_raw.Section, editable_key=True)(request.POST)
        if form.validates(request.POST):
            new_element = form.to_model()
    elif isinstance(parent, uci_raw.List):
        form = UciRawForm(uci_raw.Value, editable_key=True)(request.POST)
        if form.validates(request.POST):
            new_element = form.to_model()
    else:
        raise ValueError("New node cannot be created here.")

    if not form.valid:
        return dict(node_path=node, form=form)

    new_element.operation = "create"
    parent.add(new_element)
    print_model(new_element)
    edit_uci_config(new_element)
    bottle.redirect(reverse("uci_index"))
Example #3
0
def remove(node):
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)
    node_model.operation = "remove"
    try:
        edit_uci_config(node_model)
        bottle.redirect(reverse("uci_index") + "?done")
    except RPCError, e:
        logger.error(e.message)
Example #4
0
File: uci.py Project: jtojnar/foris
def remove(node):
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)
    node_model.operation = "remove"
    try:
        edit_uci_config(node_model)
        bottle.redirect(reverse("uci_index") + "?done")
    except RPCError, e:
        logger.error(e.message)
Example #5
0
def edit_post(node):
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)

    form = UciRawForm(type(node_model), editable_key=False)
    if form.validates(request.POST):
        form.save_to_model(node_model)
        edit_uci_config(node_model)
        bottle.redirect(reverse("uci_index") + "?done")

    return dict(form=form, node_path=node)
Example #6
0
File: uci.py Project: jtojnar/foris
def edit_post(node):
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)

    form = UciRawForm(type(node_model), editable_key=False)
    if form.validates(request.POST):
        form.save_to_model(node_model)
        edit_uci_config(node_model)
        bottle.redirect(reverse("uci_index") + "?done")

    return dict(form=form, node_path=node)
Example #7
0
    if not form.valid:
        return dict(node_path=node, form=form)

    new_element.operation = "create"
    parent.add(new_element)
    print_model(new_element)
    edit_uci_config(new_element)
    bottle.redirect(reverse("uci_index"))


@app.get("/<node:re:\w+(\.\w+)*>/remove", name="uci_remove")
@login_required
def remove(node):
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)
    node_model.operation = "remove"
    try:
        edit_uci_config(node_model)
        bottle.redirect(reverse("uci_index") + "?done")
    except RPCError, e:
        logger.error(e.message)
    bottle.redirect(reverse("uci_index") + "?error")


@app.get("/<node:re:\w+(\.\w+)*>/debug", name="uci_debug")
@login_required
def debug(node):
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)
    return "<pre>%s</pre>" % websafe(print_model(node_model))
Example #8
0
File: uci.py Project: jtojnar/foris
    if not form.valid:
        return dict(node_path=node, form=form)

    new_element.operation = "create"
    parent.add(new_element)
    print_model(new_element)
    edit_uci_config(new_element)
    bottle.redirect(reverse("uci_index"))


@app.get("/<node:re:\w+(\.\w+)*>/remove", name="uci_remove")
@login_required
def remove(node):
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)
    node_model.operation = "remove"
    try:
        edit_uci_config(node_model)
        bottle.redirect(reverse("uci_index") + "?done")
    except RPCError, e:
        logger.error(e.message)
    bottle.redirect(reverse("uci_index") + "?error")


@app.get("/<node:re:\w+(\.\w+)*>/debug", name="uci_debug")
@login_required
def debug(node):
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)
    return "<pre>%s</pre>" % websafe(print_model(node_model))