gruppenbildungsspiel/gruppenbildungsspiel.py

56 lines
1.4 KiB
Python

from flask import Flask, render_template
import uuid
import csv
import os
app = Flask(__name__)
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
datafile = "data.csv"
@app.route('/')
def index():
return render_template('index.html', title='Test', text='Hallo, Fooboar')
@app.route('/form')
def form():
id = generate_id()
return render_template('form.html', title='Test', text='Hallo, Fooboar', your_id=id)
@app.route('/result')
def result():
return render_template('result.html', hausname='Knuth', haustext='Mitglieder dieses Hauses mögen LaTeX-Anzüge und Eisbären.', id=123)
@app.route('/admin')
def admin():
return render_template('admin.html', title='Test', text='Hallo, Admin Fooboar')
@app.route('/answers')
def answers():
return render_template('answers.html', title='Test', text='Hallo, Admin Fooboar')
@app.route('/solution')
def solution():
return render_template('solution.html', title='Test', text='Hallo, Lösung')
def generate_id():
data = list()
if not os.path.exists(datafile):
open(datafile, "a").close()
with open(datafile, "r") as f:
reader = csv.reader(f)
for line in reader:
data.append(line[0])
# best loop ever
while True:
new_id = str(uuid.uuid1()).split("-")[0]
if new_id in data:
break
else:
return new_id