Exemplo n.º 1
0
Arquivo: uci.py Projeto: 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"))
Exemplo n.º 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"))
Exemplo n.º 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)
Exemplo n.º 4
0
Arquivo: uci.py Projeto: 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)
Exemplo n.º 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)
Exemplo n.º 6
0
Arquivo: uci.py Projeto: 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)
Exemplo n.º 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))
Exemplo n.º 8
0
Arquivo: uci.py Projeto: 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))