From 4ab8f23864326e2365510b4c7c01899f9a364e19 Mon Sep 17 00:00:00 2001 From: schneefux Date: Thu, 4 Feb 2016 11:15:12 +0100 Subject: list & submit POC --- app.py | 43 +++++++++++++++++++++++++++++++++++++++++++ templates/.index.html.swp | Bin 0 -> 12288 bytes templates/index.html | 20 ++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 app.py create mode 100644 templates/.index.html.swp create mode 100644 templates/index.html diff --git a/app.py b/app.py new file mode 100644 index 0000000..bcc1346 --- /dev/null +++ b/app.py @@ -0,0 +1,43 @@ +from flask import ( + Flask, + render_template, + request +) +import pymongo + + +class dbProxy(object): + def __init__(self, mongouri): + self.client = pymongo.MongoClient(mongouri) + self.db = self.client['jokevotedb'] + + def getJokes(self): + jokes = [] + for joke in self.db.jokes.find(): + jokes.append(joke) + return jokes + + def addJoke(self, text): + self.db.jokes.insert_one({'text': text, 'votes': 0}) + + +app = Flask(__name__) +db = dbProxy( + 'mongodb://jokevote:jokevote@127.0.0.1:27017/jokevotedb') + + +@app.route('/') +def root(): + jokes = db.getJokes() + return render_template('index.html', jokes=jokes) + + +@app.route('/submit', methods=['POST']) +def submit(): + text = request.form['text'] + db.addJoke(text) # TODO secure this + return root() + + +if __name__ == '__main__': + app.run(debug=True) diff --git a/templates/.index.html.swp b/templates/.index.html.swp new file mode 100644 index 0000000..b9af402 Binary files /dev/null and b/templates/.index.html.swp differ diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..2122678 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,20 @@ + + + + + Lehrerspruch-Wahlplattform + + +

Lehrersprüche

+ +
+ Neuen Spruch hinzufügen + + +
+ + -- cgit v1.3.1