Commit 0c9ce0fe authored by Jan Čermák's avatar Jan Čermák

skeleton of configuration interface (based on wizard code) - refs #2813

parent de775471
from bottle import Bottle, request, template
import bottle
import logging
from utils import login_required
import wizard
logger = logging.getLogger("admin")
app = Bottle()
handler_map = {
'password': wizard.WizardStep1,
'wan': wizard.WizardStep2,
'lan': wizard.WizardStep5,
'wifi': wizard.WizardStep6,
def get_handler(handler_name):
Handler = handler_map.get(handler_name)
if Handler is None:
raise bottle.HTTPError(404, "Unknown configuration page.")
return Handler
def render_form(form, **kwargs):
# same premise as in wizard form - we are handling single-section ForisForm
first_section = form.sections[0]
title = first_section.title
description = first_section.description
return template("config/main", form=form, title=title, description=description, **kwargs)
def config_get(handler_name):
Handler = get_handler(handler_name)
handler = Handler()
form = handler.form
return render_form(form)
@app.route("/<handler_name:re:.+>/", method="POST")
def config_post(handler_name):
Handler = get_handler(handler_name)
handler = Handler(request.POST)
if request.is_xhr:
# only update is allowed
logger.debug("ajax request")
request.POST.pop("update", None)
return dict(html=render_form(handler.form, is_xhr=True))
except TypeError:
# raised by Validator - could happen when the form is posted with wrong fields
return render_form(handler.form)
def config_ajax(handler_name):
action = request.GET.get("action")
if not action:
raise bottle.HTTPError(404, "AJAX action not specified.")
Handler = get_handler(handler_name)
handler = Handler()
result = handler.call_action(action)
return result
except ValueError:
raise bottle.HTTPError(404, "Unknown action.")
\ No newline at end of file
......@@ -4,6 +4,7 @@ import bottle
from bottle_i18n import I18NMiddleware, I18NPlugin, i18n_defaults
import gettext
import logging
import config
from nuci import client, filters
import os
import sys
......@@ -88,6 +89,7 @@ if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG if args.debug else logging.WARNING)
app =
if args.debug:
# "about:config" is available only in debug mode
%if not defined('is_xhr'):
%rebase _layout **locals()
<div id="admin-content">
%if not defined('is_xhr'):
\ No newline at end of file
%rebase config/base **locals()
<form id="wizard-main-form" class="wizard-form" action="" method="post" autocomplete="off">
<h1>{{ title }}</h1>
<p class="wizard-description">{{ description }}</p>
%for field in form.active_fields:
{{! field.label_tag }}
{{! field.render() }}
%if field.hint:
<img class="field-hint" src="/static/img/icon-help.png" title="{{ field.hint }}">
<button type="submit" name="send" class="button">{{ _("Save") }}</button>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment