From 2b26d94dd3646d9d9322c7448e80152629113e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20Ayd=C4=B1n?= <22278039+afk@users.noreply.github.com> Date: Wed, 13 Mar 2019 15:07:43 +0300 Subject: [PATCH] voting system init --- server_side/voting-system/__init__.py | 21 +++++++++++++++++++++ server_side/voting-system/db.py | 18 ++++++++++++++++++ server_side/voting-system/schema.sql | 9 +++++++++ 3 files changed, 48 insertions(+) create mode 100644 server_side/voting-system/__init__.py create mode 100644 server_side/voting-system/db.py create mode 100644 server_side/voting-system/schema.sql diff --git a/server_side/voting-system/__init__.py b/server_side/voting-system/__init__.py new file mode 100644 index 0000000..64a9132 --- /dev/null +++ b/server_side/voting-system/__init__.py @@ -0,0 +1,21 @@ +import os +from flask import Flask + +def create_app(): + app = Flask(__name__) + app.config.from_mapping( + SECRET_KEY='dev', + DATABASE=os.path.join(app.instance_path, 'voting-system.sqlite') + ) + + app.config.from_pyfile('config.py', silent=True) + try: + os.makedirs(app.instance_path) + except OSError: + pass # Already exists + + @app.route('/votings') + def hello(): + return 'Hello, world!' + + return app \ No newline at end of file diff --git a/server_side/voting-system/db.py b/server_side/voting-system/db.py new file mode 100644 index 0000000..b54b0af --- /dev/null +++ b/server_side/voting-system/db.py @@ -0,0 +1,18 @@ +import sqlite3 + +import click +from flask import current_app, g +from flask.cli import with_appcontext + +def get_db(): + if 'db' not in g: + g.db = sqlite3.connect(current_app.config['DATABASE']) + g.db.row_factory = sqlite3.Row + + return g.db + +def close_db() + db = g.pop('db', None) + + if db is not None: + db.close() \ No newline at end of file diff --git a/server_side/voting-system/schema.sql b/server_side/voting-system/schema.sql new file mode 100644 index 0000000..2c9e7b6 --- /dev/null +++ b/server_side/voting-system/schema.sql @@ -0,0 +1,9 @@ +DROP TABLE IF EXISTS votings; + +CREATE TABLE votings ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + desc TEXT, + img TEXT, + votes +) \ No newline at end of file