Skip to content
Snippets Groups Projects
Commit 21cebaa3 authored by Julian's avatar Julian
Browse files

implemented qrcode_svg template filter

parent 76b16954
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ A web service to manage LDAP users, groups and permissions. ...@@ -8,6 +8,7 @@ A web service to manage LDAP users, groups and permissions.
- python3-ldap3 - python3-ldap3
- python3-flask - python3-flask
- python3-flask-sqlalchemy - python3-flask-sqlalchemy
- python3-qrcode
- git (cli utility, musst be in path) - git (cli utility, musst be in path)
## development ## development
......
from flask import Markup
import qrcode, qrcode.image.svg
import random import random
import subprocess import subprocess
from datetime import timedelta, datetime from datetime import timedelta, datetime
import io
def register_template_helper(app): def register_template_helper(app):
# debian ships jinja2 without this test... # debian ships jinja2 without this test...
def equalto(a, b): def equalto(a, b):
return a == b return a == b
@app.template_filter()
def qrcode_svg(content, **attrs):
img = qrcode.make(content, image_factory=qrcode.image.svg.SvgPathImage)
svg = img.get_image()
for key, value, in attrs.items():
svg.set(key, value)
buf = io.BytesIO()
img.save(buf)
return Markup(buf.getvalue().decode())
@app.url_defaults @app.url_defaults
def static_version_inject(endpoint, values): #pylint: disable=unused-variable def static_version_inject(endpoint, values): #pylint: disable=unused-variable
if endpoint == 'static': if endpoint == 'static':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment