Exemple #1
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"))
Exemple #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"))
Exemple #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)
Exemple #4
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)
Exemple #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)
Exemple #6
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)