From 51cfae882bc9a710d6a297c95a70383bc2bdf96e Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Jul 09 2015 20:27:39 +0000 Subject: Stubbing out some stuff about editing hubs. --- diff --git a/hubs/app.py b/hubs/app.py index 02d481b..e7ed3c0 100644 --- a/hubs/app.py +++ b/hubs/app.py @@ -74,8 +74,8 @@ def index(): @app.route('//') def hub(name): hub = get_hub(session, name) - return flask.render_template('hubs.html', hub=hub, session=session) - + return flask.render_template( + 'hubs.html', hub=hub, session=session, edit=False) @app.route('//json') @app.route('//json/') @@ -86,11 +86,28 @@ def hub_json(name): return response +@app.route('//edit', methods=['GET']) +@app.route('//edit/', methods=['GET']) +def hub_edit_get(name): + hub = get_hub(session, name) + return flask.render_template( + 'hubs.html', hub=hub, session=session, edit=True) + + +@app.route('//edit', methods=['POST']) +@app.route('//edit/', methods=['POST']) +def hub_edit_post(name): + #hub = get_hub(session, name) + # TODO -- save things to the db ... and then redirect + raise NotImplementedError('TODO - save changes to hub config') + flask.redirect(flask.url_for('hub', name=name)) + + @app.route('//') @app.route('///') def widget_render(hub, idx): widget = get_widget(session, hub, idx) - return widget.render(session) + return widget.render(session, edit=False) @app.route('///json') @@ -102,6 +119,25 @@ def widget_json(hub, idx): return response +@app.route('///edit', methods=['GET']) +@app.route('///edit/', methods=['GET']) +def widget_edit_get(hub, idx): + widget = get_widget(session, hub, idx) + raise NotImplementedError('next step is to get the widgets to render ' + 'editable versions of themselves with their ' + 'declared @arguments, etc...') + return widget.render(session, edit=True) + + +@app.route('///edit', methods=['POST']) +@app.route('///edit/', methods=['POST']) +def widget_edit_post(hub, idx): + #widget = get_widget(session, hub, idx) + # TODO -- save things to the db ... and then redirect + raise NotImplementedError('TODO - save changes to widget config') + flask.redirect(flask.url_for('hub', name=hub)) + + @app.route('/source/') @app.route('/source//') def widget_source(name): diff --git a/hubs/templates/hubs.html b/hubs/templates/hubs.html index 79ef909..680ed62 100644 --- a/hubs/templates/hubs.html +++ b/hubs/templates/hubs.html @@ -67,7 +67,7 @@

{{hub.name}}

{{hub.summary}}
- {% if g.auth.logged_in and hub.is_admin(g.auth.user) %} + {% if g.auth.logged_in and not edit and hub.is_admin(g.auth.user) %}

edit this hub

{% endif %}
@@ -81,12 +81,32 @@ {% for widget in hub.left_widgets %}
{% endfor %} + + {% if edit %} +
+
+ +
+
+ {% endif %}
{% for widget in hub.right_widgets %}
{% endfor %} + + {% if edit %} +
+
+ +
+
+ {% endif %}
@@ -97,7 +117,11 @@ var widgets = [{% for widget in hub.widgets %}'{{ widget.idx }}',{% endfor %}]; $.each(widgets, function(i, widget) { $.ajax({ + {% if edit %} + url: widget + '/edit/', + {% else %} url: widget, + {% endif %} dataType: 'html', success: function(html) { $('#widget-' + widget).html(html);