]> git.aero2k.de Git - sirius.git/commitdiff
Add view to test quips.
authorTom Hunger <tehunger@gmail.com>
Wed, 4 Feb 2015 20:10:47 +0000 (20:10 +0000)
committerTom Hunger <tehunger@gmail.com>
Wed, 4 Feb 2015 20:10:47 +0000 (20:10 +0000)
sirius/web/admin.py
sirius/web/templates/admin.html

index 4d70b86ba8ea1576c03fc57932b180dfadc1932d..a58d94dbe6aed0904fb16178f98389c97cffa0df 100644 (file)
@@ -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')
index 75a27c7f36f774a8e8658878a721c2abe4d2ce7c..3ed125ac5aed167a2c407dcc83381c2cd8bf3f0b 100644 (file)
@@ -5,7 +5,12 @@
 {% block page_content %}
 <h1>Admin!</h1>
 
-<form method="post">
+<form method="post" action="/admin/randomly-change-personality">
        <button>change personality randomly</button>
 </form>
+
+<form method="post" action="/admin/randomly-change-quip">
+       <button>change quip randomly</button>
+</form>
+
 {% endblock %}