You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
from io import BytesIO
|
|
|
|
import qrcode
|
|
|
|
from flask import send_file, flash
|
|
|
|
|
|
|
|
def generate_qr_code(url):
|
|
|
|
qr = qrcode.QRCode(
|
|
|
|
version=None,
|
|
|
|
error_correction=qrcode.constants.ERROR_CORRECT_M,
|
|
|
|
box_size=30,
|
|
|
|
border=4,
|
|
|
|
)
|
|
|
|
qr.add_data(url)
|
|
|
|
qr.make(fit=True)
|
|
|
|
return qr.make_image(fill_color='black', back_color='white')
|
|
|
|
|
|
|
|
def serve_pil_image(pil_img):
|
|
|
|
# Source: https://stackoverflow.com/questions/7877282/how-to-send-image-generated-by-pil-to-browser
|
|
|
|
img_io = BytesIO()
|
|
|
|
pil_img.save(img_io, 'PNG', quality=70)
|
|
|
|
img_io.seek(0)
|
|
|
|
return send_file(img_io, mimetype='image/png')
|
|
|
|
|
|
|
|
def flash_errors(form):
|
|
|
|
"""Flashes form errors"""
|
|
|
|
print('a')
|
|
|
|
for field, errors in form.errors.items():
|
|
|
|
for error in errors:
|
|
|
|
flash(u"Error in the %s field - %s" % (
|
|
|
|
getattr(form, field).label.text,
|
|
|
|
error
|
|
|
|
), 'error')
|