-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from vshn/pimped-printing
New label printing
- Loading branch information
Showing
13 changed files
with
284 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,7 +231,7 @@ command_chaos=sh -c "notify-send -t 2000 $(curl -s -u username:password http://l | |
### Contactform with Printer | ||
|
||
The Contactform app lives in the `contactform/` folder. | ||
It serves two main purposes: | ||
It serves these purposes: | ||
|
||
* Collecting leads at the conference booth and store them in Odoo as CRM lead | ||
* Printing of labels for all kind of fun, for example for the booth raffle | ||
|
@@ -243,7 +243,17 @@ It allows configuration of the Odoo campaign name, the label header and can opti | |
As the application runs directly on the Raspberry Pi, it needs to be available on the Internet, so that a booth visitor can directly access it. | ||
This is made possible with FRP, see next section. | ||
|
||
The label printing was made possible thanks to the fantastic [brother_ql_web](https://github.com/FriedrichFroebel/brother_ql_web/) Python module. | ||
The label printing is made possible thanks to the fantastic [brother_ql_web](https://github.com/FriedrichFroebel/brother_ql_web/) Python module. | ||
|
||
#### APPUiO Voucher | ||
|
||
The app generates an APPUiO Voucher and prints it on a label. | ||
The generated QR code links to https://www.appuio.ch/sign-up with URL parameters to prefill the form fields for user convenience: | ||
|
||
`?voucher=abc123&company=XYZ&name=John%20Doe&[email protected]&phone=123456789` | ||
|
||
For this form field pre-filling to work, a small JavaScript snippet (`hack/field-values-from-url.js`) needs to be available in the APPUiO website. | ||
It is added into a `<script>` tag via the theme configuration in Odoo. | ||
|
||
### Connectivity from the Internet | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import logging | ||
from flask import flash | ||
from wtforms.fields import * | ||
from html2image import Html2Image | ||
from brother_ql_web.labels import ( | ||
LabelParameters, | ||
generate_label, | ||
print_label, | ||
) | ||
from brother_ql.backends.network import BrotherQLBackendNetwork | ||
|
||
|
||
def print_raffle(form, config, printer_config): | ||
label_filename = "label_raffle.png" | ||
|
||
label_css = """ | ||
body, html { | ||
margin: 0; | ||
padding: 0; | ||
height: 100%; | ||
display: grid; | ||
place-items: center; | ||
font-family: sans-serif; | ||
text-align: center; | ||
} | ||
h1 { | ||
font-size: 70px; | ||
} | ||
p { | ||
font-size: 35px; | ||
} | ||
""" | ||
label_html = f"""\ | ||
<div> | ||
<h1>{form.name.data}</h1> | ||
<p>{config.LABEL_HEADER}</p> | ||
</div> | ||
""" | ||
|
||
hti = Html2Image() | ||
hti.size = (590, 300) | ||
hti.screenshot( | ||
html_str=label_html, | ||
css_str=label_css, | ||
save_as=label_filename, | ||
) | ||
|
||
label_image = open(label_filename, "rb") | ||
|
||
parameters = LabelParameters( | ||
configuration=printer_config, | ||
image=label_image.read(), | ||
label_size="54", | ||
) | ||
|
||
logging.info(f"Printing raffle label for {form.name.data}") | ||
qlr = generate_label( | ||
parameters=parameters, | ||
configuration=printer_config, | ||
save_image_to=( | ||
"print-preview-raffle.png" if config.LOG_LEVEL == "DEBUG" else None | ||
), | ||
) | ||
try: | ||
print_label( | ||
parameters=parameters, | ||
qlr=qlr, | ||
configuration=printer_config, | ||
backend_class=BrotherQLBackendNetwork, | ||
) | ||
except Exception as e: | ||
flash(f"Printing of raffle ticket failed: {e}", "error") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import segno | ||
import urllib | ||
import logging | ||
|
||
|
||
from flask import flash | ||
from wtforms.fields import * | ||
from html2image import Html2Image | ||
from brother_ql_web.labels import ( | ||
LabelParameters, | ||
generate_label, | ||
print_label, | ||
) | ||
from brother_ql.backends.network import BrotherQLBackendNetwork | ||
|
||
|
||
def print_voucher(form, voucher_code, config, printer_config): | ||
label_filename = "label_voucher.png" | ||
qr_code_filename = "appuio_voucher_qr.png" | ||
|
||
label_css = """ | ||
body, html { | ||
margin: 0; | ||
padding: 0; | ||
height: 100%; | ||
display: grid; | ||
place-items: center; | ||
font-family: sans-serif; | ||
text-align: center; | ||
} | ||
.logo { | ||
width: 70%; | ||
} | ||
.text { | ||
font-size: 45px; | ||
} | ||
.text_small { | ||
font-size: 35px; | ||
} | ||
""" | ||
label_html = f"""\ | ||
<div> | ||
<p><img src="appuio-bw.png" class="logo"></p> | ||
<p class="text">Hi {form.name.data}<p> | ||
<p class="text">Your personal voucher code to try out APPUiO:</p> | ||
<p class="text"><strong>{voucher_code}</strong></p> | ||
<p class="text_small">Register here: {config.APPUIO_SIGNUP_URL}</p> | ||
<p><img src="{qr_code_filename}"></p> | ||
</div> | ||
""" | ||
|
||
registration_url_parameters = ( | ||
f"?voucher={voucher_code}" | ||
f"&name={urllib.parse.quote(form.name.data)}" | ||
f"&company={urllib.parse.quote(form.company.data)}" | ||
f"&email={urllib.parse.quote(form.email.data)}" | ||
f"&phone={urllib.parse.quote(form.phone.data)}" | ||
) | ||
qrcode = segno.make_qr(f"{config.APPUIO_SIGNUP_URL}{registration_url_parameters}") | ||
qrcode.save( | ||
qr_code_filename, | ||
scale=5, | ||
) | ||
|
||
hti = Html2Image(size=(590, 1050)) | ||
hti.load_file("contactform/static/images/appuio-bw.png") | ||
hti.load_file(qr_code_filename) | ||
hti.browser.print_command = True if config.LOG_LEVEL == "DEBUG" else False | ||
hti.screenshot( | ||
html_str=label_html, | ||
css_str=label_css, | ||
save_as=label_filename, | ||
) | ||
|
||
label_image = open(label_filename, "rb") | ||
|
||
parameters = LabelParameters( | ||
configuration=printer_config, | ||
image=label_image.read(), | ||
label_size="54", | ||
high_quality=True, | ||
) | ||
|
||
logging.info(f"Printing voucher label for {form.name.data}") | ||
qlr = generate_label( | ||
parameters=parameters, | ||
configuration=printer_config, | ||
save_image_to=( | ||
"print-preview-voucher.png" if config.LOG_LEVEL == "DEBUG" else None | ||
), | ||
) | ||
try: | ||
print_label( | ||
parameters=parameters, | ||
qlr=qlr, | ||
configuration=printer_config, | ||
backend_class=BrotherQLBackendNetwork, | ||
) | ||
except Exception as e: | ||
flash(f"Printing of voucher failed: {e}", "error") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.