collect ALL the data
This commit is contained in:
commit
20e5b88dae
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.*.swp
|
||||||
|
db.sqlite
|
||||||
|
/venv/
|
11
datentrog
Normal file
11
datentrog
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/ksh
|
||||||
|
|
||||||
|
daemon="/var/lib/datentrog/venv/bin/python3 /var/lib/datentrog/datentrog.py"
|
||||||
|
daemon_user="datentrog"
|
||||||
|
|
||||||
|
. /etc/rc.d/rc.subr
|
||||||
|
|
||||||
|
rc_bg=YES
|
||||||
|
rc_reload=NO
|
||||||
|
|
||||||
|
rc_cmd $1
|
54
datentrog.py
Executable file
54
datentrog.py
Executable file
|
@ -0,0 +1,54 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import bottle
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
|
application = bottle.default_app()
|
||||||
|
connection = sqlite3.connect("db.sqlite")
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS visitors (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
event TEXT,
|
||||||
|
time DATETIME,
|
||||||
|
name TEXT,
|
||||||
|
address TEXT,
|
||||||
|
contact TEXT
|
||||||
|
);
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
@application.get("/")
|
||||||
|
@bottle.view("datentrog.tpl")
|
||||||
|
def datentrog_get():
|
||||||
|
return dict(event=bottle.request.query.get("event", "Heizhaus"))
|
||||||
|
|
||||||
|
|
||||||
|
@application.post("/")
|
||||||
|
@bottle.view("datentrog.tpl")
|
||||||
|
def datentrog_post():
|
||||||
|
data = {"feedback": True, "success": True}
|
||||||
|
for field in ("event", "name", "address", "contact"):
|
||||||
|
data[field] = bottle.request.forms.get(field, "")
|
||||||
|
data["success"] = data["success"] and data[field]
|
||||||
|
if data["success"]:
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO visitors (event, time, name, address, contact)
|
||||||
|
VALUES (:event, datetime('now'), :name, :address, :contact);
|
||||||
|
""", data)
|
||||||
|
connection.commit()
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@application.get("/cleanup")
|
||||||
|
def cleanup():
|
||||||
|
cursor.execute("""
|
||||||
|
DELETE FROM visitors WHERE time < datetime('now', '-1 month');
|
||||||
|
""")
|
||||||
|
connection.commit()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
bottle.run(host="0.0.0.0", port=8080)
|
||||||
|
else:
|
||||||
|
application.catchall = False
|
50
datentrog.tpl
Normal file
50
datentrog.tpl
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Corona-Kontaktformular - {{ get("event", "Heizhaus") }}</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Corona-Kontaktformular</h1>
|
||||||
|
% if get("success", False):
|
||||||
|
<p>Erfolgreich registriert.</p>
|
||||||
|
<form method="get">
|
||||||
|
<input type="hidden" name="event" value="{{ get("event", "Heizhaus") }}">
|
||||||
|
<button type="submit" class="btn btn-primary">Weitere Person registrieren</button>
|
||||||
|
</form>
|
||||||
|
% else:
|
||||||
|
<p>Die Daten werden nach 1 Monat gelöscht und ausschließlich zur Corona-Kontaktverfolgung verwendet.</p>
|
||||||
|
<form method="post" autocomplete="on">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="event">Veranstaltung:</label>
|
||||||
|
<input id="event" class="form-control" name="event" value="{{ get("event", "Heizhaus") }}" readonly>
|
||||||
|
</div>
|
||||||
|
<div class="form-group {{ ("has-success" if get("name", False) else "has-error") + " has-feedback" if get("feedback", False) else "" }}">
|
||||||
|
<label for="name">Name, Vorname:</label>
|
||||||
|
<input id="name" class="form-control" placeholder="Söder, Markus" name="name" value="{{ get("name", "") }}" required>
|
||||||
|
% if get("feedback", False):
|
||||||
|
<span class="glyphicon {{ "glyphicon-ok" if get("name", False) else "glyphicon-remove" }} form-control-feedback"></span>
|
||||||
|
% end
|
||||||
|
</div>
|
||||||
|
<div class="form-group {{ ("has-success" if get("address", False) else "has-error") + " has-feedback" if get("feedback", False) else "" }}">
|
||||||
|
<label for="address">Adresse:</label>
|
||||||
|
<input id="address" class="form-control" placeholder="Jakobstraße 46, 90402 Nürnberg" name="address" value="{{ get("address", "") }}" required>
|
||||||
|
% if get("feedback", False):
|
||||||
|
<span class="glyphicon {{ "glyphicon-ok" if get("address", False) else "glyphicon-remove" }} form-control-feedback"></span>
|
||||||
|
% end
|
||||||
|
</div>
|
||||||
|
<div class="form-group {{ ("has-success" if get("contact", False) else "has-error") + " has-feedback" if get("feedback", False) else "" }}">
|
||||||
|
<label for="contact">Email/Telefon:</label>
|
||||||
|
<input id="contact" class="form-control" placeholder="markus.soeder@soeder.de" name="contact" value="{{ get("contact", "") }}" required>
|
||||||
|
% if get("feedback", False):
|
||||||
|
<span class="glyphicon {{ "glyphicon-ok" if get("contact", False) else "glyphicon-remove" }} form-control-feedback"></span>
|
||||||
|
% end
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-success">Registrieren</button>
|
||||||
|
</form>
|
||||||
|
% end
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
bottle
|
Loading…
Reference in a new issue