diff --git a/livesync/indico_livesync/controllers.py b/livesync/indico_livesync/controllers.py index 307a65d..db2802c 100644 --- a/livesync/indico_livesync/controllers.py +++ b/livesync/indico_livesync/controllers.py @@ -18,16 +18,16 @@ from __future__ import unicode_literals from flask import request, redirect, flash from flask_pluginengine import render_plugin_template, current_plugin +from werkzeug.exceptions import NotFound from indico.core.db import db from indico.modules.admin import RHAdminBase from indico.web.flask.util import url_for from indico.web.forms.base import FormDefaults -from indico.web.util import jsonify_data +from indico.web.util import jsonify_data, jsonify_template from indico_livesync import _ from indico_livesync.models.agents import LiveSyncAgent -from indico_livesync.views import WPLiveSync def extend_plugin_details(): @@ -52,7 +52,10 @@ class RHAddAgent(RHAdminBase): def _checkParams(self): self.backend_name = request.view_args['backend'] - self.backend = current_plugin.backend_classes[self.backend_name] + try: + self.backend = current_plugin.backend_classes[self.backend_name] + except KeyError: + raise NotFound def _process(self): form = self.backend.form(obj=FormDefaults(name=self.backend.title)) @@ -63,9 +66,9 @@ class RHAddAgent(RHAdminBase): db.session.add(agent) flash(_('Agent added'), 'success') flash(_("Don't forget to run the initial export!"), 'highlight') - return redirect(url_for('plugins.details', plugin='livesync')) + return jsonify_data(flash=False) - return WPLiveSync.render_template('edit_agent.html', form=form, backend=self.backend) + return jsonify_template('edit_agent.html', render_plugin_template, form=form, backend=self.backend, edit=False) class RHEditAgent(RHAdminBase): @@ -78,12 +81,13 @@ class RHEditAgent(RHAdminBase): return redirect(url_for('plugins.details', plugin='livesync')) def _process(self): - form = self.agent.backend.form(obj=FormDefaults(self.agent, {'name'}, **self.agent.settings)) + form = self.agent.backend.form(obj=FormDefaults(name=self.agent.name, **self.agent.settings)) if form.validate_on_submit(): data = form.data self.agent.name = data.pop('name') self.agent.settings = data flash(_('Agent updated'), 'success') - return redirect(url_for('plugins.details', plugin='livesync')) + return jsonify_data(flash=False) - return WPLiveSync.render_template('edit_agent.html', form=form, backend=self.agent.backend, agent=self.agent) + return jsonify_template('edit_agent.html', render_plugin_template, form=form, backend=self.agent.backend, + edit=True) diff --git a/livesync/indico_livesync/templates/edit_agent.html b/livesync/indico_livesync/templates/edit_agent.html index 9cee2d8..27af138 100644 --- a/livesync/indico_livesync/templates/edit_agent.html +++ b/livesync/indico_livesync/templates/edit_agent.html @@ -1,27 +1,10 @@ -{% extends 'layout/base.html' %} -{% from 'forms/_form.html' import form_header, form_row, form_footer %} - -{% block title %}LiveSync{% endblock %} - -{% block subtitle %} - {%- if agent -%} - {% trans %}Edit Agent{% endtrans %} - {%- else -%} - {% trans backend=backend.title %}Add {{ backend }} agent{% endtrans %} - {%- endif -%} -{% endblock %} +{% extends 'layout/dialog_base.html' %} +{% from 'forms/_form.html' import simple_form %} {% block description %} {{ backend.description }} {% endblock %} {% block content %} - {{ form_header(form) }} - {% for field in form.visible_fields %} - {{ form_row(field) }} - {% endfor %} - {% call form_footer(form) %} - - {% trans %}Cancel{% endtrans %} - {% endcall %} + {{ simple_form(form, back=_('Cancel'), disabled_until_change=edit) }} {% endblock %} diff --git a/livesync/indico_livesync/templates/plugin_details_extra.html b/livesync/indico_livesync/templates/plugin_details_extra.html index 666f24d..1db3158 100644 --- a/livesync/indico_livesync/templates/plugin_details_extra.html +++ b/livesync/indico_livesync/templates/plugin_details_extra.html @@ -1,3 +1,20 @@ +{% from 'message_box.html' import message_box %} + +{% macro add_agent_link(name, backend, standalone=false) %} + + {% if standalone %} + {% trans backend=backend.title %}Add {{ backend }} agent{% endtrans %} + {% else %} + {{ backend.title }} + {% endif %} + +{% endmacro %} +
-{#- Don't "fix" the indentation of these lines! -#}
-{%- for agent in missing_initial_export -%}
-indico livesync initial_export {{ agent.id }}
-{% endfor -%}
+ {%- filter dedent %}
+ {%- for agent in missing_initial_export -%}
+ indico livesync initial_export {{ agent.id }}
+ {% endfor -%}
+ {% endfilter -%}
{% endif %}