]> git.aero2k.de Git - sirius.git/commitdiff
Add a switch to choose wether or not you want to print a face
authorQuentin Dufour <quentin@dufour.tk>
Mon, 1 May 2017 13:49:06 +0000 (15:49 +0200)
committerQuentin Dufour <quentin@dufour.tk>
Mon, 1 May 2017 13:49:06 +0000 (15:49 +0200)
README.md
sirius/web/printer_print.py
sirius/web/templates/printer_print.html

index 5f06b0466f3f9b98d112774138c1a8e98f506c55..293102f64cfc58c46bf029959c1b7af3d20eb21f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ Differences with the original project :
    * Add links from the community
    * Add a guide for Debian
  * Recommend PhantomJS 2.1.1 to support pictures
- * Deactivate face printing by default (will add a switch soon)
+ * Deactivate face printing by default
  * Add an API Key to make requests progamatically (will add documentation soon)
 
 ## Using it
index 2c2eeaadb7dcc2ff6169d33c48fc0571d6e6dd16..9f7ba53a675f4278ea11628d20e16a2426c4de94 100644 (file)
@@ -25,6 +25,11 @@ class PrintForm(flask_wtf.Form):
         coerce=int,
         validators=[wtforms.validators.DataRequired()],
     )
+    face = wtforms.SelectField(
+        'Face',
+        coerce=int,
+        validators=[wtforms.validators.DataRequired()],
+    )
     message = wtforms.TextAreaField(
         'Message',
         validators=[wtforms.validators.DataRequired()],
@@ -60,20 +65,30 @@ def printer_print(printer_id):
         (x.id, x.name) for x in login.current_user.friends_printers()
     ]
     form.target_printer.choices = choices
+    form.face.choices = [(1, "Default face"), (2, "No face")]
 
     # Set default printer on get
     if flask.request.method != 'POST':
         form.target_printer.data = printer.id
+        form.face.data = 1
 
     if form.validate_on_submit():
         # TODO: move image encoding into a pthread.
         # TODO: use templating to avoid injection attacks
         pixels = image_encoding.default_pipeline(
             templating.default_template(form.message.data))
-        hardware_message = messages.SetDeliveryAndPrintNoFace(
-            device_address=printer.device_address,
-            pixels=pixels,
-        )
+
+        hardware_message = None
+        if form.face.data == 1:
+            hardware_message = messages.SetDeliveryAndPrintNoFace(
+                device_address=printer.device_address,
+                pixels=pixels,
+            )
+        else:
+            hardware_message = messages.SetDeliveryAndPrint(
+                device_address=printer.device_address,
+                pixels=pixels,
+            )
 
         # If a printer is "offline" then we won't find the printer
         # connected and success will be false.
index 75dce3a87ffce6d1981f6434774c129119c054d5..2ea06870deb90833198749149bef823cee2e99ed 100644 (file)
                        </ul>
                        {% endif %}
                        {{ form.target_printer(class="form-control") }}
+    </div>
+    <div class="form-group {% if form.face.errors %}has-error{% endif%}">
+                               <label>{{ form.face.label }}</label>
+                       {% if form.face.errors %}
+                       <ul>
+                       {% for error in form.face.errors %}
+                       <li>{{ error }}</li>
+                       {% endfor %}
+                       </ul>
+                       {% endif %}
+                       {{ form.face(class="form-control") }}
                </div>
+
                <div class="form-group {% if form.message.errors %}has-error{% endif%}">
                        <label>{{ form.message.label }}</label>
                        {% if form.message.errors %}