예제 #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"))
예제 #2
0
파일: uci.py 프로젝트: 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"))
예제 #3
0
def edit(node):
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)

    form = UciRawForm(type(node_model), editable_key=False)
    form.fill_from_uci(node_model)

    return dict(form=form, node_path=node)
예제 #4
0
파일: uci.py 프로젝트: jtojnar/foris
def edit(node):
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)

    form = UciRawForm(type(node_model), editable_key=False)
    form.fill_from_uci(node_model)

    return dict(form=form, node_path=node)
예제 #5
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)
예제 #6
0
파일: uci.py 프로젝트: 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)
예제 #7
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)
예제 #8
0
파일: uci.py 프로젝트: 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)
예제 #9
0
파일: uci.py 프로젝트: jtojnar/foris
def create(node):
    operation = request.GET.get("operation")
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)
    if type(node_model) is uci_raw.Section:
        # Section contains lists or options
        if operation == "add-list":
            form = UciRawForm(uci_raw.List, editable_key=True)
        elif operation == "add-option":
            form = UciRawForm(uci_raw.Option, editable_key=True)
        else:
            raise ValueError("Requested operation not allowed for Section node.")
    elif type(node_model) is uci_raw.Config:
        # Config consists of Sections
        form = UciRawForm(uci_raw.Section, editable_key=True)
    elif type(node_model) is uci_raw.List:
        # List consists of Values
        form = UciRawForm(uci_raw.Value, editable_key=True)
    else:
        raise ValueError("New node cannot be created here.")

    return dict(node_path=node, form=form)
예제 #10
0
def create(node):
    operation = request.GET.get("operation")
    uci_model = client.get_uci_config()
    node_model = uci_model.find_child(node)
    if type(node_model) is uci_raw.Section:
        # Section contains lists or options
        if operation == "add-list":
            form = UciRawForm(uci_raw.List, editable_key=True)
        elif operation == "add-option":
            form = UciRawForm(uci_raw.Option, editable_key=True)
        else:
            raise ValueError(
                "Requested operation not allowed for Section node.")
    elif type(node_model) is uci_raw.Config:
        # Config consists of Sections
        form = UciRawForm(uci_raw.Section, editable_key=True)
    elif type(node_model) is uci_raw.List:
        # List consists of Values
        form = UciRawForm(uci_raw.Value, editable_key=True)
    else:
        raise ValueError("New node cannot be created here.")

    return dict(node_path=node, form=form)
예제 #11
0
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))
예제 #12
0
def index():
    uci_model = client.get_uci_config()
    node_path = request.GET.get("node")
    return dict(tree=uci_model,
                node=None,
                node_path=node_path.split(".") if node_path else None)
예제 #13
0
파일: uci.py 프로젝트: jtojnar/foris
def index():
    uci_model = client.get_uci_config()
    node_path = request.GET.get("node")
    return dict(tree=uci_model, node=None,
                node_path=node_path.split(".") if node_path else None)
예제 #14
0
파일: uci.py 프로젝트: jtojnar/foris
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))