diff --git a/model/__init__.py b/model/__init__.py index 00f6a66afc90a1fd204ed346b7de8afd16ac35d8..230d3c2c368b7d2dc82a337b9b83ba1b0edd4c68 100644 --- a/model/__init__.py +++ b/model/__init__.py @@ -9,6 +9,6 @@ class BaseModel(Model): class Meta(): database = sqlite -from model.base import Question, Answer +from model.base import Question, Answer, Submit -sqlite.create_tables([Question, Answer]) \ No newline at end of file +sqlite.create_tables([Question, Answer, Submit]) \ No newline at end of file diff --git a/model/base.py b/model/base.py index a07290d721a626272f2f763a6a309cb7d28f0185..422d93c85297018a5c6e9d3421aaf1c797674ce2 100644 --- a/model/base.py +++ b/model/base.py @@ -6,12 +6,12 @@ class Question(BaseModel): text = CharField() +class Submit(BaseModel): + + token = CharField() class Answer(BaseModel): text = CharField() question = ForeignKeyField(Question, backref="answers") - - - -class Submit(BaseModel): \ No newline at end of file + submit = ForeignKeyField(Submit, backref="answers") diff --git a/model/cfd.sqlite b/model/cfd.sqlite index fc807d34a5181a296fed86f491c8a4274c302768..aacce7d740fb0d62dbc3ff70496c13758831ffc2 100644 Binary files a/model/cfd.sqlite and b/model/cfd.sqlite differ diff --git a/static/LNP300_blue.jpg b/static/LNP300_blue.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1c8cad5ef6ff0cf8462faa2d175f1274d25296d3 Binary files /dev/null and b/static/LNP300_blue.jpg differ diff --git a/static/LNP300_green.jpg b/static/LNP300_green.jpg new file mode 100644 index 0000000000000000000000000000000000000000..9caaaf624bc130e41c55f82c41f0399a22fb17c5 Binary files /dev/null and b/static/LNP300_green.jpg differ diff --git a/static/LNP300_green.jpg~ b/static/LNP300_green.jpg~ new file mode 100644 index 0000000000000000000000000000000000000000..8870337ffea536b9fc9a31e79a7d055b87efbccf Binary files /dev/null and b/static/LNP300_green.jpg~ differ diff --git a/static/LNP300_green.png b/static/LNP300_green.png new file mode 100644 index 0000000000000000000000000000000000000000..82c0de3406a4f0731a4897abb0dcbb8e508878c9 Binary files /dev/null and b/static/LNP300_green.png differ diff --git a/static/PressStart2P-Regular.ttf b/static/PressStart2P-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..39adf42efa597906e53be689474ac82214112124 Binary files /dev/null and b/static/PressStart2P-Regular.ttf differ diff --git a/static/main.css b/static/main.css new file mode 100644 index 0000000000000000000000000000000000000000..59fdfeeaacb41563de65ca4bc1a840699f424329 --- /dev/null +++ b/static/main.css @@ -0,0 +1,62 @@ +@font-face { font-family: PressStart2P; src: url('../../static/PressStart2P-Regular.ttf'); } + + +.vertical-center { + min-height: 100%; /* Fallback for browsers do NOT support vh unit */ + min-height: 100vh; /* These two lines are counted as one :-) */ + + display: flex; + align-items: center; + } +.my-auto { + margin-top: auto; +margin-bottom: auto; +} +.hor-cent { + margin: 0 auto; + border-radius: 10px; + width: 40%; + background-color: black; + color: white; + position: relative; +} + +.imgplacer { + margin: 0 auto; + width: 50%; +} + +img { + width: 100%; +} + +.fw { + width: 100%; +} + +.ccc-blue{ + color: #0084b0; +} + +.ccc-green{ + color: #00a356; +} + +.white{ + color: white; +} + +body { + + background-color: #232323; + font-family: PressStart2P; +} + +@media (max-width: 1275.98px) { + .hor-cent { + width:90%; + } + .imgplacer { + width: 60%; + } +} diff --git a/templates/feedback.jinja b/templates/feedback.jinja new file mode 100644 index 0000000000000000000000000000000000000000..7fc0744e4f669a4cdb2c2b876056cb23a2bc2f04 --- /dev/null +++ b/templates/feedback.jinja @@ -0,0 +1,5 @@ +{% extends "main.jinja" %} + +{% block content%} + {{message}} +{% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 0a063097d8b28bc9ae89dee62745a1a1e8b984e9..0000000000000000000000000000000000000000 --- a/templates/index.html +++ /dev/null @@ -1,17 +0,0 @@ -<html> - <head></head> - <body> - <form action="/submit" method="POST"> - {% for quest in questions %} - {% set questid = quest.id %} - {% set questtext = quest.text %} - {{ questtext }} - <br> - <input type="hidden" name="question_ids[]" value="{{questid}}"/> - <input type="text" name="{{questid}}" value=""> - <br><br> - {% endfor %} - <input type="submit" value="Submit"> - </form> - </body> -</html> \ No newline at end of file diff --git a/templates/index.jinja b/templates/index.jinja new file mode 100644 index 0000000000000000000000000000000000000000..3e51804fa93cfd65ffe7a7fa24667ae592a7fbfb --- /dev/null +++ b/templates/index.jinja @@ -0,0 +1,17 @@ +{% extends "main.jinja" %} + +{% block content%} + Trage hier deine Antworten ein:<br><br> + <form action="/submit" method="POST"> + {% for quest in questions %} + {% set questid = quest.id %} + {% set questtext = quest.text %} + {{ questtext }} + <br> + <input class="form-control" type="hidden" name="question_ids[]" value="{{questid}}"/> + <input class="form-control" type="text" name="{{questid}}" value=""> + <br><br> + {% endfor %} + <input type="submit" value="Submit"> + </form> +{% endblock %} diff --git a/templates/main.jinja b/templates/main.jinja new file mode 100644 index 0000000000000000000000000000000000000000..cbd966a1d3b984bf21f3df4fab3657f4a6e22b08 --- /dev/null +++ b/templates/main.jinja @@ -0,0 +1,25 @@ +<html> + <head> + <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> + <link rel="stylesheet" href="/static/main.css"> + </head> + <body> + <div class="container-fluid"> + <div class="row p-3 m-2"> + <div class="col-3"> + + </div> + <div class="col-6"> + <h3 class="ccc-blue">Chaos-Familien-Duell</h3> + <div class="imgplacer"> + <img src="/static/LNP300_green.png" alt="lnp300-logo"> + </div> + <div class="white"> + {% block content %} + {% endblock %} + </div> + </div> + </div> + </div> + </body> +</html> diff --git a/view/questions.py b/view/questions.py index 0a66525084a5fe685fb0e5e1b2f6b83cb589ea24..c8de6d7fd879ed2e2b57d03f87a626ef4841381d 100644 --- a/view/questions.py +++ b/view/questions.py @@ -1,13 +1,15 @@ import uuid from flask import Flask, render_template, redirect, request, Blueprint, session -from model import Question, Answer +from model import Question, Answer, Submit questions = Blueprint("questions", "questions") @questions.route("/") def index(): - return render_template("index.html", questions=Question.select()) + if "token" in session: + return render_template("feedback.jinja", message="Vielen Dank für deine Antworten!") + return render_template("index.jinja", questions=Question.select()) @questions.route("/debug") def debug(): @@ -21,20 +23,23 @@ def submit_answers(): if "token" in session: return "nanan, du hast schon!" - session["token"] = uuid.uuid4() + token = uuid.uuid4() + session["token"] = token + + submit = Submit.get_or_create(token=token)[0] question_ids = request.form.getlist("question_ids[]") if question_ids is None: - return "No answers submitted!" + return render_template("feedback.jinja", message="ERROR: Keine Question-ID übermittelt!") for question_id in question_ids: question = Question.get_or_none(id=question_id) if question is None: - return "No question found by that id %s" % question_id + return render_template("feedback.jinja", message="ERROR: Keine Frage mit der ID '%s' gefunden" % question_id) answer = request.form.get(question_id) - answer = Answer.create(text=answer, question=question) + answer = Answer.create(text=answer, question=question, submit=submit) answer.save() - return "Vielen Dankeschön" \ No newline at end of file + return render_template("feedback.jinja", message="Vielen Dank für deine Antworten!") \ No newline at end of file