From 732c9cb4b4a31ba72314e0b4f76064ab850bd5f8 Mon Sep 17 00:00:00 2001 From: "Sachin S. Kamath" <sskamath96@gmail.com> Date: Thu, 19 Oct 2017 15:57:55 +0530 Subject: [PATCH] Restructure code and add user model Signed-off-by: Sachin S. Kamath <sskamath96@gmail.com> --- .gitignore | 1 + hodor/__init__.py | 46 +++++++++++++++++++++++++------------- hodor/controllers/index.py | 19 ---------------- hodor/models/index.py | 11 --------- hodor/settings/.keep | 0 requirements.txt | 11 ++++----- runserver.py | 8 +++---- 7 files changed, 39 insertions(+), 57 deletions(-) delete mode 100644 hodor/controllers/index.py delete mode 100644 hodor/models/index.py delete mode 100644 hodor/settings/.keep diff --git a/.gitignore b/.gitignore index 976a9c7..248fb04 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,4 @@ venv.bak/ # Jetbrains folders .idea/ +migrations/ diff --git a/hodor/__init__.py b/hodor/__init__.py index a313df1..61b6d17 100644 --- a/hodor/__init__.py +++ b/hodor/__init__.py @@ -1,19 +1,35 @@ -# -*- coding: utf-8 -*- -__version__ = '0.1' -from flask import Flask -from flask_debugtoolbar import DebugToolbarExtension +# app/__init__.py +import time +from flask_api import FlaskAPI +from flask_sqlalchemy import SQLAlchemy +# local import +from instance.config import app_config -ENV = 'development' +# initialize sql-alchemy +db = SQLAlchemy() -app = Flask('hodor') -app.config['SECRET_KEY'] = 'CHANGE_ME_IN_PRODUCTION' +from hodor.models import * -from hodor.controllers import * -if ENV == 'development': - app.debug = True - toolbar = DebugToolbarExtension(app) -else: - app.debug = False - if app.config['SECRET_KEY'] == 'CHANGE_ME_IN_PRODUCTION': - print("[!] Please change your secret key before running in production"); +def create_app(config_name): + app = FlaskAPI(__name__, instance_relative_config=True) + app.config.from_object(app_config[config_name]) + app.config.from_pyfile('config.py') + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False + db.init_app(app) + if config_name != 'production': + for x in range(0,5): + print "*** YOU ARE NOT RUNNING THE APP IN PRODUCTION MODE!! *** CTRL + C TO ABORT. APP WILL RUN IN {} SECONDS".format(5-x) + time.sleep(1) + + if config_name == 'production': + app.config['DEFAULT_RENDERERS'] = [ + 'flask.ext.api.renderers.JSONRenderer', + ] + + return app + + +app = create_app('testing') + +from hodor.controllers import * diff --git a/hodor/controllers/index.py b/hodor/controllers/index.py deleted file mode 100644 index 922aec5..0000000 --- a/hodor/controllers/index.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -from hodor import app -from flask import render_template, request -from flask_wtf import FlaskForm -from wtforms import StringField -from wtforms.validators import DataRequired - - -class CreateForm(FlaskForm): - text = StringField('name', validators=[DataRequired()]) - - -@app.route('/') -def start(): - pass - -@app.route('/app') -def application(): - pass diff --git a/hodor/models/index.py b/hodor/models/index.py deleted file mode 100644 index 54ff974..0000000 --- a/hodor/models/index.py +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -from flask import flash - - -class Printer(object): - - def show_string(self, text): - if text == '': - flash("You didn't enter any text to flash") - else: - flash(text + "!!!") diff --git a/hodor/settings/.keep b/hodor/settings/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/requirements.txt b/requirements.txt index e0cb3ec..0ce32c8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,4 @@ -Flask==0.12.2 -Flask-DebugToolbar==0.10.1 -Flask-SocketIO==2.9.1 -Flask-WTF==0.14.2 -Jinja2==2.9.6 -virtualenv -flask-restful +Flask +Flask-WTF +Jinja2 +Flask-DebugToolbar diff --git a/runserver.py b/runserver.py index c532c4a..4b3da66 100755 --- a/runserver.py +++ b/runserver.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -import os from hodor import app +config_name = 'development' + if __name__ == '__main__': - port = int(os.environ.get("PORT", 8080)) - app.run('0.0.0.0', port=port) + app.run() \ No newline at end of file -- GitLab