provide qr codes for printing
This commit is contained in:
parent
a02d190438
commit
49bbe12917
29
datentrog.py
29
datentrog.py
|
@ -1,5 +1,8 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import bottle
|
import bottle
|
||||||
|
import io
|
||||||
|
import qrcode
|
||||||
|
import qrcode.image.styledpil as qrstyled
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,6 +21,13 @@ cursor.execute("""
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
def url(route):
|
||||||
|
return '%s://%s/%s' % (
|
||||||
|
bottle.request.urlparts.scheme,
|
||||||
|
bottle.request.urlparts.netloc,
|
||||||
|
route)
|
||||||
|
|
||||||
|
|
||||||
@application.get("/")
|
@application.get("/")
|
||||||
@bottle.view("template/new.tpl")
|
@bottle.view("template/new.tpl")
|
||||||
def new_get():
|
def new_get():
|
||||||
|
@ -29,7 +39,7 @@ def new_get():
|
||||||
def new_post():
|
def new_post():
|
||||||
event = bottle.request.forms.get("event", "")
|
event = bottle.request.forms.get("event", "")
|
||||||
if event:
|
if event:
|
||||||
bottle.redirect("event/" + event)
|
bottle.redirect(url("qr/" + event))
|
||||||
return dict(event=event, feedback=True)
|
return dict(event=event, feedback=True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +48,23 @@ def static_get(file):
|
||||||
return bottle.static_file(file, root="static")
|
return bottle.static_file(file, root="static")
|
||||||
|
|
||||||
|
|
||||||
|
@application.get("/qr/<event>")
|
||||||
|
@bottle.view("template/qr.tpl")
|
||||||
|
def qr_get(event):
|
||||||
|
return dict(event=event, url=url("event/" + event))
|
||||||
|
|
||||||
|
|
||||||
|
@application.get("/qr/img/<event>.png")
|
||||||
|
def qr_img_get(event):
|
||||||
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=20)
|
||||||
|
qr.add_data(url("event/" + event))
|
||||||
|
image = qr.make_image(image_factory=qrstyled.StyledPilImage, embeded_image_path="heizhaus_logo_square.png")
|
||||||
|
buffer = io.BytesIO()
|
||||||
|
image.save(buffer, format="PNG")
|
||||||
|
bottle.response.content_type = "image/png"
|
||||||
|
return buffer.getvalue()
|
||||||
|
|
||||||
|
|
||||||
@application.get("/event/<event>")
|
@application.get("/event/<event>")
|
||||||
@bottle.view("template/event.tpl")
|
@bottle.view("template/event.tpl")
|
||||||
def event_get(event):
|
def event_get(event):
|
||||||
|
|
BIN
heizhaus_logo.png
Normal file
BIN
heizhaus_logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
BIN
heizhaus_logo_circle.png
Normal file
BIN
heizhaus_logo_circle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
BIN
heizhaus_logo_square.png
Normal file
BIN
heizhaus_logo_square.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -1 +1,2 @@
|
||||||
bottle
|
bottle
|
||||||
|
qrcode[pil]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
% rebase('template/toplevel.tpl', title=event)
|
% rebase("template/toplevel.tpl", title=event)
|
||||||
% if get("success", False):
|
% if get("success", False):
|
||||||
<div class="alert alert-success">Erfolgreich registriert.</div>
|
<div class="alert alert-success">Erfolgreich registriert.</div>
|
||||||
<form method="get">
|
<form method="get">
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
% rebase('template/toplevel.tpl', title='Neu erstellen')
|
% rebase("template/toplevel.tpl", title="Neu erstellen")
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="form-group {{ ("has-success" if get("event", False) else "has-error") + " has-feedback" if get("feedback", False) else "" }}">
|
<div class="form-group {{ ("has-success" if get("event", False) else "has-error") + " has-feedback" if get("feedback", False) else "" }}">
|
||||||
<label for="event">Veranstaltungsort:</label>
|
<label for="event">Veranstaltungsort:</label>
|
||||||
<input id="event" class="form-control" placeholder="Kunstrasen" name="event" value="{{ get("event", "") }}">
|
<input id="event" class="form-control" placeholder="Heizhaus" name="event" value="{{ get("event", "") }}">
|
||||||
% if get("feedback", False):
|
% if get("feedback", False):
|
||||||
<span class="glyphicon {{ "glyphicon-ok" if get("event", False) else "glyphicon-remove" }} form-control-feedback"></span>
|
<span class="glyphicon {{ "glyphicon-ok" if get("event", False) else "glyphicon-remove" }} form-control-feedback"></span>
|
||||||
% end
|
% end
|
||||||
|
|
7
template/qr.tpl
Normal file
7
template/qr.tpl
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
% rebase("template/toplevel.tpl", title=event)
|
||||||
|
<div class="hidden-print">
|
||||||
|
<a class="btn btn-default" href="{{ url }}">Zum Formular</a>
|
||||||
|
<button class="btn btn-primary" onclick="window.print()">Drucken</button>
|
||||||
|
</div>
|
||||||
|
<img class="img-responsive" src="img/{{ event }}.png" alt="QR-Code">
|
||||||
|
<p class="lead">{{ url }}</p>
|
Loading…
Reference in a new issue