From: Quentin Dufour Date: Mon, 1 May 2017 13:49:06 +0000 (+0200) Subject: Add a switch to choose wether or not you want to print a face X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=64ef0ad42eaa1dac995a2648505fd2bd13bd6dab;p=sirius.git Add a switch to choose wether or not you want to print a face --- diff --git a/README.md b/README.md index 5f06b04..293102f 100644 --- 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 diff --git a/sirius/web/printer_print.py b/sirius/web/printer_print.py index 2c2eeaa..9f7ba53 100644 --- a/sirius/web/printer_print.py +++ b/sirius/web/printer_print.py @@ -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. diff --git a/sirius/web/templates/printer_print.html b/sirius/web/templates/printer_print.html index 75dce3a..2ea0687 100644 --- a/sirius/web/templates/printer_print.html +++ b/sirius/web/templates/printer_print.html @@ -20,7 +20,19 @@ {% endif %} {{ form.target_printer(class="form-control") }} + +
+ + {% if form.face.errors %} + + {% endif %} + {{ form.face(class="form-control") }}
+
{% if form.message.errors %}