Commit abfd7a2e authored by Jan Čermák's avatar Jan Čermák

refactoring: init app's routes in init() method of modules

parent 1406ff23
......@@ -36,10 +36,6 @@ from utils.routing import reverse
logger = logging.getLogger(__name__)
app = Bottle()
app.install(CSRFPlugin())
class ConfigPageMixin(object):
template = "config/main"
......@@ -297,7 +293,6 @@ def get_config_page(page_name):
return ConfigPage
@app.route("/", name="config_index")
@login_required
def index():
notifications = client.get_messages()
......@@ -307,7 +302,6 @@ def index():
notifications=notifications.new)
@app.route("/notifications/dismiss", method="POST")
@login_required
def dismiss_notifications():
message_ids = request.POST.getall("message_ids[]")
......@@ -317,7 +311,6 @@ def dismiss_notifications():
return {'success': False}
@app.route("/<page_name:re:.+>/", name="config_page")
@login_required
def config_page_get(page_name):
ConfigPage = get_config_page(page_name)
......@@ -326,7 +319,6 @@ def config_page_get(page_name):
active_config_page_key=page_name)
@app.route("/<page_name:re:.+>/", method="POST")
@login_required
def config_page_post(page_name):
ConfigPage = get_config_page(page_name)
......@@ -346,7 +338,6 @@ def config_page_post(page_name):
active_config_page_key=page_name)
@app.route("/<page_name:re:.+>/action/<action:re:.+>", name="config_action")
@login_required
def config_action(page_name, action):
ConfigPage = get_config_page(page_name)
......@@ -358,7 +349,6 @@ def config_action(page_name, action):
raise bottle.HTTPError(404, "Unknown action.")
@app.route("/<page_name:re:.+>/action/<action:re:.+>", method="POST")
@login_required
def config_action_post(page_name, action):
ConfigPage = get_config_page(page_name)
......@@ -386,7 +376,6 @@ def config_action_post(page_name, action):
raise bottle.HTTPError(404, "Unknown action.")
@app.route("/<page_name:re:.+>/ajax", name="config_ajax", method=("GET", "POST"))
@login_required
def config_ajax(page_name):
action = request.params.get("action")
......@@ -399,3 +388,22 @@ def config_ajax(page_name):
return result
except ValueError:
raise bottle.HTTPError(404, "Unknown action.")
def init():
app = Bottle()
app.install(CSRFPlugin())
app.route("/", name="config_index", callback=index)
app.route("/notifications/dismiss", method="POST",
callback=dismiss_notifications)
app.route("/<page_name:re:.+>/ajax", name="config_ajax", method=("GET", "POST"),
callback=config_ajax)
app.route("/<page_name:re:.+>/action/<action:re:.+>", method="POST",
callback=config_action_post)
app.route("/<page_name:re:.+>/action/<action:re:.+>", name="config_action",
callback=config_action)
app.route("/<page_name:re:.+>/", method="POST",
callback=config_page_post)
app.route("/<page_name:re:.+>/", name="config_page",
callback=config_page_get)
return app
......@@ -314,8 +314,8 @@ def prepare_main_app(args):
# mount apps
import config
import wizard
app.mount("/config", config.app)
app.mount("/wizard", wizard.app)
app.mount("/config", config.init())
app.mount("/wizard", wizard.init())
if args.debug:
# "about:config" is available only in debug mode
......
......@@ -32,10 +32,6 @@ from utils.routing import reverse
logger = logging.getLogger("wizard")
app = Bottle()
app.install(CSRFPlugin())
NUM_WIZARD_STEPS = 9
......@@ -353,9 +349,6 @@ class WizardStep9(WizardStepMixin, BaseConfigHandler):
can_skip_wizard=self.can_skip_wizard, **kwargs)
app = Bottle()
def get_wizard(number):
"""WizardStep class factory.
......@@ -467,7 +460,7 @@ def mark_wizard_finished_session():
session["wizard_finished"] = True
session.save()
@app.route("/step/<number:re:\d+>/ajax")
@login_required
def ajax(number=1):
check_step_allowed_or_redirect(number)
......@@ -483,13 +476,11 @@ def ajax(number=1):
raise bottle.HTTPError(404, "Unknown Wizard action.")
@app.route("/", name="wizard_index")
@login_required
def wizard():
return bottle.template("wizard/index")
@app.route("/step/<number:re:\d+>", name="wizard_step")
@login_required
def step(number=1):
Wizard = get_wizard(number)
......@@ -497,7 +488,6 @@ def step(number=1):
return wiz.render(stepnumber=number)
@app.route("/step/<number:re:\d+>", method="POST")
@login_required
def step_post(number=1):
Wizard = get_wizard(number)
......@@ -518,7 +508,6 @@ def step_post(number=1):
return wiz.render(stepnumber=number)
@app.route("/skip", name="wizard_skip")
@login_required
def skip():
allowed_step_max, wizard_finished = get_wizard_progress()
......@@ -535,3 +524,14 @@ def skip():
bottle.redirect(reverse("config_index"))
raise bottle.HTTPError(403, "Action not allowed.")
def init():
app = Bottle()
app.install(CSRFPlugin())
app.route("/step/<number:re:\d+>/ajax", callback=ajax)
app.route("/", name="wizard_index", callback=wizard)
app.route("/step/<number:re:\d+>", name="wizard_step", callback=step)
app.route("/step/<number:re:\d+>", method="POST", callback=step_post)
app.route("/skip", name="wizard_skip", callback=skip)
return app
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