Create id submission field for answers
This commit is contained in:
parent
eb79fc572a
commit
e398cfe7e6
@ -29,6 +29,23 @@ class QuestionForm(Form):
|
||||
check = BooleanField('Bitte nicht ankreuzen')
|
||||
email = EmailField('Email-Adresse')
|
||||
|
||||
|
||||
def create_used_id_list():
|
||||
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])
|
||||
print(data)
|
||||
return data
|
||||
|
||||
class AnswerForm(Form):
|
||||
user_id = StringField('Deine Id', [validators.InputRequired(), validators.AnyOf(values=create_used_id_list(), message='Leider ist das keine gültige ID')])
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html', title='Sortierhut')
|
||||
@ -49,7 +66,7 @@ def questions():
|
||||
# user.name = form.username
|
||||
# spirit = request.form['spirit_animal']
|
||||
# user.save()
|
||||
return redirect(url_for('result'))
|
||||
return redirect(url_for('result', user_id=new_id))
|
||||
return render_template('questions.html', form=form)
|
||||
|
||||
# @app.route('/form')
|
||||
@ -57,33 +74,36 @@ def questions():
|
||||
# id = generate_id()
|
||||
# return render_template('form.html', title='Sortierhut', 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('/result<user_id>')
|
||||
def result(user_id):
|
||||
return render_template('result.html', hausname='Knuth', haustext='Mitglieder dieses Hauses mögen LaTeX-Anzüge und Eisbären.', id=user_id)
|
||||
|
||||
@app.route('/admin')
|
||||
def admin():
|
||||
return render_template('admin.html', title='Sortierhut', text='Hallo, Admin Fooboar')
|
||||
|
||||
@app.route('/answers')
|
||||
@app.route('/answers', methods=['GET', 'POST'])
|
||||
def answers():
|
||||
return render_template('answers.html', title='Sortierhut', text='Hallo, Admin Fooboar')
|
||||
form = AnswerForm(request.form)
|
||||
if request.method == 'POST' and form.validate():
|
||||
ident = request.form['user_id']
|
||||
return redirect(url_for('view_answers', user_id=ident))
|
||||
return render_template('answers.html', form=form, title='Sortierhut', text='Hallo, Admin Fooboar')
|
||||
|
||||
@app.route('/view_answers<user_id>')
|
||||
def view_answers(user_id):
|
||||
return render_template('view.html', title='Sortierhut', user_id=user_id)
|
||||
|
||||
@app.route('/solution')
|
||||
def solution():
|
||||
return render_template('solution.html', title='Sortierhut', text='Hallo, Lösung')
|
||||
|
||||
@app.route('/patrons')
|
||||
def patrons():
|
||||
return render_template('patrons.html', title='Sortierhut')
|
||||
|
||||
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])
|
||||
|
||||
data = create_used_id_list()
|
||||
# best loop ever
|
||||
while True:
|
||||
new_id = str(uuid.uuid1()).split("-")[0]
|
||||
|
||||
@ -1 +1,9 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
{% from "_formhelpers.html" import render_field %}
|
||||
<form method=post>
|
||||
{{ render_field(form.user_id) }}
|
||||
<p></p>
|
||||
<p><input type=submit value=Abschicken>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
1
templates/patrons.html
Normal file
1
templates/patrons.html
Normal file
@ -0,0 +1 @@
|
||||
{% extends "base.html" %}
|
||||
4
templates/view.html
Normal file
4
templates/view.html
Normal file
@ -0,0 +1,4 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<h1>Deine Antworten, liebe*r {{ user_id }}!</h1>
|
||||
{% endblock %}
|
||||
Loading…
x
Reference in New Issue
Block a user