Commit 908d05e6 authored by Jan Čermák's avatar Jan Čermák

WIzardStepMixin and ConfigPageMixin call_action refactoring - split into...

WIzardStepMixin and ConfigPageMixin call_action refactoring - split into call_action and call_ajax_action
parent 11a38b81
......@@ -35,6 +35,22 @@ app.install(CSRFPlugin())
class ConfigPageMixin(object):
template = "config/main"
def call_action(self, action):
"""Call config page action.
:param action:
:return: object that can be passes as HTTP response to Bottle
"""
raise bottle.HTTPError(404, "No actions specified for this page.")
def call_ajax_action(self, action):
"""Call AJAX action.
:param action:
:return: dict of picklable AJAX results
"""
raise bottle.HTTPError(404, "No AJAX actions specified for this page.")
def default_template(self, **kwargs):
return template(self.template, **kwargs)
......@@ -76,12 +92,7 @@ class AboutConfigPage(ConfigPageMixin):
def _action_registration_code(self):
return client.get_registration()
def call_action(self, action):
"""Call AJAX action.
:param action:
:return: dict of picklable AJAX results
"""
def call_ajax_action(self, action):
if action == "registration_code":
regnum = self._action_registration_code()
if regnum:
......@@ -155,6 +166,18 @@ def config_page_post(page_name):
return config_page.render(active_handler_key=page_name)
@app.route("/<page_name:re:.+>/action/<action:re:.*>")
@login_required
def config_action(page_name, action):
ConfigPage = get_config_page(page_name)
config_page = ConfigPage()
try:
result = config_page.call_action(action)
return result
except ValueError:
raise bottle.HTTPError(404, "Unknown action.")
@app.route("/<page_name:re:.+>/ajax")
@login_required
def config_ajax(page_name):
......@@ -164,7 +187,7 @@ def config_ajax(page_name):
ConfigPage = get_config_page(page_name)
config_page = ConfigPage()
try:
result = config_page.call_action(action)
result = config_page.call_ajax_action(action)
return result
except ValueError:
raise bottle.HTTPError(404, "Unknown action.")
\ No newline at end of file
......@@ -45,6 +45,22 @@ class WizardStepMixin(object):
# wizard step name
can_skip_wizard = True
def call_action(self, action):
"""Call config page action.
:param action:
:return: object that can be passes as HTTP response to Bottle
"""
raise bottle.HTTPError(404, "No actions specified for this page.")
def call_ajax_action(self, action):
"""Call AJAX action.
:param action:
:return: dict of picklable AJAX results
"""
raise bottle.HTTPError(404, "No AJAX actions specified for this page.")
def allow_next_step(self):
# this function can be used as a callback for a form
if self.next_step_allowed is not None:
......@@ -151,7 +167,7 @@ class WizardStep4(WizardStepMixin, BaseConfigHandler):
def _action_updater_status(self):
return client.get_updater_status()
def call_action(self, action):
def call_ajax_action(self, action):
if action == "run_updater":
run_success = self._action_run_updater()
return dict(success=run_success)
......@@ -275,7 +291,7 @@ def ajax(number=1):
Wizard = get_wizard(number)
wiz = Wizard()
try:
result = wiz.call_action(action)
result = wiz.call_ajax_action(action)
return result
except ValueError:
raise bottle.HTTPError(404, "Unknown Wizard action.")
......
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