commit 949086d60554cdf30af48738b61e978a82ee3508 Author: Daniel Tsvetkov Date: Wed Mar 18 10:59:37 2020 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c40623 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.idea +venv +*.pyc +data/db.sqlite +__pycache__ \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..d88d0b1 --- /dev/null +++ b/config.py @@ -0,0 +1,10 @@ +import os + +basepath = os.path.dirname(os.path.realpath(__file__)) + +DATA_DIR = os.path.join(basepath, "data") +DATABASE_FILE = os.path.join(DATA_DIR, "db.sqlite") +SQLALCHEMY_DATABASE_URI = 'sqlite:///{}'.format(DATABASE_FILE) +MAKEDIRS = [ + DATA_DIR, +] diff --git a/oshipka.py b/oshipka.py new file mode 100644 index 0000000..50adb87 --- /dev/null +++ b/oshipka.py @@ -0,0 +1,7 @@ +from persistance.populate import init_db +from webapp import app + +if __name__ == "__main__": + init_db(app) + + app.run(debug=True) diff --git a/persistance/__init__.py b/persistance/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/persistance/models.py b/persistance/models.py new file mode 100644 index 0000000..61e2559 --- /dev/null +++ b/persistance/models.py @@ -0,0 +1,8 @@ +import json +import os + +from flask import render_template, request +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy_utils import ChoiceType + +db = SQLAlchemy() \ No newline at end of file diff --git a/persistance/populate.py b/persistance/populate.py new file mode 100644 index 0000000..93f2830 --- /dev/null +++ b/persistance/populate.py @@ -0,0 +1,22 @@ +import os + +from config import SQLALCHEMY_DATABASE_URI, MAKEDIRS, DATABASE_FILE +from persistance.models import db + + +def populate_db(app): + with app.app_context(): + pass + + +def init_db(app): + app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI + app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False + + db.init_app(app) + for dir in MAKEDIRS: + os.makedirs(dir, exist_ok=True) + if not os.path.exists(DATABASE_FILE): + with app.app_context(): + db.create_all() + populate_db(app) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8f8c054 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +click==7.1.1 +Flask==1.1.1 +Flask-SQLAlchemy==2.4.1 +itsdangerous==1.1.0 +Jinja2==2.11.1 +MarkupSafe==1.1.1 +SQLAlchemy==1.3.15 +Werkzeug==1.0.0 diff --git a/webapp/__init__.py b/webapp/__init__.py new file mode 100644 index 0000000..5a43827 --- /dev/null +++ b/webapp/__init__.py @@ -0,0 +1,4 @@ +from flask import Flask + +app = Flask(__name__) +app.config["SECRET_KEY"] = "UNSECRET_KEY....478932fjkdsl"