From: Tom Hunger Date: Wed, 4 Feb 2015 20:10:47 +0000 (+0000) Subject: Add view to test quips. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=7c5710ee23fb7fd5cf8e0ecba4ff57ce508279c1;p=sirius.git Add view to test quips. --- diff --git a/sirius/web/admin.py b/sirius/web/admin.py index 4d70b86..a58d94d 100644 --- a/sirius/web/admin.py +++ b/sirius/web/admin.py @@ -11,7 +11,14 @@ from sirius.coding import image_encoding blueprint = flask.Blueprint('admin', __name__) -@blueprint.route('/admin/randomly-change-personality', methods=['GET', 'POST']) + +@blueprint.route('/admin', methods=['GET']) +def admin_landing(): + return flask.render_template( + 'admin.html', + ) + +@blueprint.route('/admin/randomly-change-personality', methods=['POST']) def randomly_change_personality(): # Restrict to debug for now until we have a proper user management # system. @@ -19,26 +26,46 @@ def randomly_change_personality(): im = image_encoding.threshold(Image.open('./tests/normalface.png')) - if flask.request.method == 'POST': - msg = messages.SetPersonality( - device_address='000d6f000273ce0b', - face_pixels=im, - nothing_to_print_pixels=im, - cannot_see_bridge_pixels=im, - cannot_see_internet_pixels=im, - ) - success, next_print_id = protocol_loop.send_message( - '000d6f000273ce0b', msg) - - if success: - flask.flash('Sent your message to the printer!') - else: - flask.flash(("Could not send message because the " - "printer {} is offline.").format('000d6f000273ce0b'), - 'error') - - return flask.redirect(flask.request.path) + msg = messages.SetPersonality( + device_address='000d6f000273ce0b', + face_pixels=im, + nothing_to_print_pixels=im, + cannot_see_bridge_pixels=im, + cannot_see_internet_pixels=im, + ) + success, next_print_id = protocol_loop.send_message( + '000d6f000273ce0b', msg) - return flask.render_template( - 'admin.html', + if success: + flask.flash('Sent your message to the printer!') + else: + flask.flash(("Could not send message because the " + "printer {} is offline.").format('000d6f000273ce0b'), + 'error') + + return flask.redirect('/admin') + + +@blueprint.route('/admin/randomly-change-quip', methods=['GET', 'POST']) +def randomly_change_quip(): + # Restrict to debug for now until we have a proper user management + # system. + assert flask.current_app.config['DEBUG'], "Debug not enabled" + + msg = messages.SetQuip( + device_address='000d6f000273ce0b', + quip_pixels_1=image_encoding.default_pipeline('quip 1'), + quip_pixels_2=image_encoding.default_pipeline('quip 2'), + quip_pixels_3=image_encoding.default_pipeline('quip 3'), ) + success, next_print_id = protocol_loop.send_message( + '000d6f000273ce0b', msg) + + if success: + flask.flash('Sent your message to the printer!') + else: + flask.flash(("Could not send message because the " + "printer {} is offline.").format('000d6f000273ce0b'), + 'error') + + return flask.redirect('/admin') diff --git a/sirius/web/templates/admin.html b/sirius/web/templates/admin.html index 75a27c7..3ed125a 100644 --- a/sirius/web/templates/admin.html +++ b/sirius/web/templates/admin.html @@ -5,7 +5,12 @@ {% block page_content %}

Admin!

-
+
+ +
+ +
+ {% endblock %}