From 34f70ff88260b3dd943943ea3ebbb49997bf9b2c Mon Sep 17 00:00:00 2001 From: reverend <reverend@reverend2048.de> Date: Fri, 26 Apr 2019 22:38:22 +0200 Subject: [PATCH] ~soo wenig zeit argragr --- .gitignore | 101 +++++++++++++++++++++++++++++++++++++++++++ main.py | 64 ++------------------------- model/__init__.py | 3 +- model/base.py | 7 ++- model/cfd.sqlite | Bin 0 -> 16384 bytes templates/index.html | 5 ++- view/questions.py | 40 +++++++++++++++++ 7 files changed, 155 insertions(+), 65 deletions(-) create mode 100644 .gitignore create mode 100644 model/cfd.sqlite create mode 100644 view/questions.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9d8a865 --- /dev/null +++ b/.gitignore @@ -0,0 +1,101 @@ +*.pyc +lib/python3.7/site-packages/werkzeug/wrappers/__pycache__/__init__.cpython-37.pyc +lib/python3.7/__pycache__/site.cpython-37.pyc +lib/python3.7/site-packages/__pycache__/peewee.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/__init__.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/_compat.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/_unicodefun.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/core.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/decorators.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/exceptions.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/formatting.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/globals.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/parser.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/termui.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/types.cpython-37.pyc +lib/python3.7/site-packages/click/__pycache__/utils.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/__init__.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/_compat.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/app.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/blueprints.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/cli.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/config.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/ctx.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/debughelpers.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/globals.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/helpers.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/logging.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/sessions.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/signals.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/templating.cpython-37.pyc +lib/python3.7/site-packages/flask/__pycache__/wrappers.cpython-37.pyc +lib/python3.7/site-packages/flask/json/__pycache__/__init__.cpython-37.pyc +lib/python3.7/site-packages/flask/json/__pycache__/tag.cpython-37.pyc +lib/python3.7/site-packages/itsdangerous/__pycache__/__init__.cpython-37.pyc +lib/python3.7/site-packages/itsdangerous/__pycache__/_compat.cpython-37.pyc +lib/python3.7/site-packages/itsdangerous/__pycache__/_json.cpython-37.pyc +lib/python3.7/site-packages/itsdangerous/__pycache__/encoding.cpython-37.pyc +lib/python3.7/site-packages/itsdangerous/__pycache__/exc.cpython-37.pyc +lib/python3.7/site-packages/itsdangerous/__pycache__/jws.cpython-37.pyc +lib/python3.7/site-packages/itsdangerous/__pycache__/serializer.cpython-37.pyc +lib/python3.7/site-packages/itsdangerous/__pycache__/signer.cpython-37.pyc +lib/python3.7/site-packages/itsdangerous/__pycache__/timed.cpython-37.pyc +lib/python3.7/site-packages/itsdangerous/__pycache__/url_safe.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/__init__.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/_compat.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/_identifier.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/asyncfilters.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/asyncsupport.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/bccache.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/compiler.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/debug.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/defaults.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/environment.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/exceptions.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/ext.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/filters.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/idtracking.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/lexer.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/loaders.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/nodes.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/optimizer.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/parser.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/runtime.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/tests.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/utils.cpython-37.pyc +lib/python3.7/site-packages/jinja2/__pycache__/visitor.cpython-37.pyc +lib/python3.7/site-packages/markupsafe/__pycache__/__init__.cpython-37.pyc +lib/python3.7/site-packages/markupsafe/__pycache__/_compat.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/__init__.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/_compat.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/_internal.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/_reloader.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/datastructures.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/exceptions.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/filesystem.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/formparser.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/http.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/local.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/routing.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/security.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/serving.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/urls.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/utils.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/__pycache__/wsgi.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/debug/__pycache__/__init__.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/debug/__pycache__/console.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/debug/__pycache__/repr.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/debug/__pycache__/tbtools.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/middleware/__pycache__/__init__.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/middleware/__pycache__/dispatcher.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/middleware/__pycache__/http_proxy.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/middleware/__pycache__/shared_data.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/wrappers/__pycache__/accept.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/wrappers/__pycache__/auth.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/wrappers/__pycache__/base_request.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/wrappers/__pycache__/base_response.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/wrappers/__pycache__/common_descriptors.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/wrappers/__pycache__/etag.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/wrappers/__pycache__/request.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/wrappers/__pycache__/response.cpython-37.pyc +lib/python3.7/site-packages/werkzeug/wrappers/__pycache__/user_agent.cpython-37.pyc diff --git a/main.py b/main.py index 2b9d754..e618dd7 100644 --- a/main.py +++ b/main.py @@ -1,63 +1,7 @@ from flask import Flask -from flask import render_template -import random -from flask import request -from peewee import * - -db = SqliteDatabase('cfd.db') - -class Answer(Model): - q1 = CharField() - q2 = CharField() - q3 = CharField() - q4 = CharField() - q5 = CharField() - q6 = CharField() - q7 = CharField() - q8 = CharField() - q9 = CharField() - q10 = CharField() - class Meta: - database = db - -questions = [["wie heisst du?",0], - ["wo wohnst du?",1], - ["brot?",2], - ["was ist das beste hackaspace",3], - ["lol",4], - ["lel",5], - ["lul",6], - ["lal",7], - ["loel",8], - ["lil",9]] +from view.questions import questions app = Flask(__name__) - -@app.route("/") -def start(): - return render_template("index.html",questions=questions) - -@app.route("/submit", methods=["POST"]) -def submit(): - answers = [] - for x in range(len(questions)): - answers.append(request.form.get(str(x))) - print(questions[x][0],request.form.get(str(x))) - entr = Answer(q1=answers[0], - q2=answers[1], - q3=answers[2], - q4=answers[3], - q5=answers[4], - q6=answers[5], - q7=answers[6], - q8=answers[7], - q9=answers[8], - q10=answers[9]) - entr.save() - return "danki" - - -if __name__ == "__main__": - db.connect() - db.create_tables([q1,q2,q3,q4,q5,q6,q7,q8,q9,10]) - app.run() \ No newline at end of file +app.config['SECRET_KEY'] = 'blubb' +app.register_blueprint(questions) +app.run(debug=True) diff --git a/model/__init__.py b/model/__init__.py index f99f84a..00f6a66 100644 --- a/model/__init__.py +++ b/model/__init__.py @@ -9,5 +9,6 @@ class BaseModel(Model): class Meta(): database = sqlite +from model.base import Question, Answer -sqlite.create_tables([Team, Game, Round, Question, Answer]) \ No newline at end of file +sqlite.create_tables([Question, Answer]) \ No newline at end of file diff --git a/model/base.py b/model/base.py index ed94838..a07290d 100644 --- a/model/base.py +++ b/model/base.py @@ -5,10 +5,13 @@ from model import BaseModel class Question(BaseModel): text = CharField() - id = CharField() class Answer(BaseModel): text = CharField() - Question = ForeignKeyField(Quesiton, backref="answers") + question = ForeignKeyField(Question, backref="answers") + + + +class Submit(BaseModel): \ No newline at end of file diff --git a/model/cfd.sqlite b/model/cfd.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..fc807d34a5181a296fed86f491c8a4274c302768 GIT binary patch literal 16384 zcmeI%F>ljA6bJA-pHtgN^pGHg43(~4l1K#sRTdTq={1C=4!D7|s;VkgOt9J{B6gq> zQ;?AO4$ORtN^E=tCKe`y#KgkHz}cxoAQfU@sL=l;=brDKpYML#IUDzDe&~ru{Xw@C zie+++P)cqIK?q5!OIKIYm<p!vX_ELupC(tX-Z-l!u=yt8ujY?bhXw%%KmY;|fB*y_ z009U<00RGyz#cO)*RphE_`SAw*y;t(yut31p%;XHzqjkR$0K^#m8FIhRcA$R3VU{% zE$U7(Zi~D<RlzQd?rKIRo24)MVQcTe8$Uh%WyggZrQ0<*UBGYK>TL~Kk*;v+4dFbf z)x<rwx?Xa(#G2e%5_aevhPHTEa?5v0ZvJ|)SeVRI+36L`R9X_Nbyrp^PE_jm<qB7> zN>@5%x$(11v?;ZwLg6VjG7AfIbTi&d@|L96e%((peEjsxI{tn~h3IUq@wbG3RzGME zfB*y_009U<00Izz00bZa0SKHzfxN~@v*``QWA*2K+v|xnZ$A*NVW4gXVx=E=qT}r! zw1(kD%E)qM7^*qz{Xs`{HNQ6u7NhgO$)6MciGSel_z{1@U-Or001W~VfB*y_009U< z00Izz00bZafqx-jnmRd8L%*wCFm!U+>cpq>?)Y@BhRwN2K6PSVpXAv|c}vqtnr`QE zJK80xlcKeqi#`A(=l_P^UCiyAQ9CjDd&0l-ukkm4Z~P1Ys0Pp=009U<00Izz00bZa k0SG_<0uVUe0x3qRX6nqMMjXyXVJZ&wC}eS{F=kmm0G86wSpWb4 literal 0 HcmV?d00001 diff --git a/templates/index.html b/templates/index.html index 3235c9e..0a06309 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,10 +3,11 @@ <body> <form action="/submit" method="POST"> {% for quest in questions %} - {% set questid = quest[1] %} - {% set questtext = quest[0] %} + {% 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 %} diff --git a/view/questions.py b/view/questions.py new file mode 100644 index 0000000..0a66525 --- /dev/null +++ b/view/questions.py @@ -0,0 +1,40 @@ +import uuid + +from flask import Flask, render_template, redirect, request, Blueprint, session +from model import Question, Answer + +questions = Blueprint("questions", "questions") + +@questions.route("/") +def index(): + return render_template("index.html", questions=Question.select()) + +@questions.route("/debug") +def debug(): + Question.create(text="Guten Morgen Linus!") + Question.create(text="Wer hat den Keks aus der Dose geklaut") + return "nice" + +@questions.route("/submit", methods=["POST"]) +def submit_answers(): + + if "token" in session: + return "nanan, du hast schon!" + + session["token"] = uuid.uuid4() + + question_ids = request.form.getlist("question_ids[]") + + if question_ids is None: + return "No answers submitted!" + + 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 + + answer = request.form.get(question_id) + answer = Answer.create(text=answer, question=question) + answer.save() + + return "Vielen Dankeschön" \ No newline at end of file -- GitLab