Parcourir la source

Commit inicial

Oscar Alfredo Leiva Salomón il y a 6 ans
Parent
commit
76c39bb453
10 fichiers modifiés avec 103 ajouts et 0 suppressions
  1. 6 0
      .vscode/settings.json
  2. 0 0
      README.md
  3. 8 0
      app/__init__.py
  4. 9 0
      app/main/__init__.py
  5. 38 0
      app/main/config.py
  6. 0 0
      app/main/resources/__init__.py
  7. 6 0
      app/main/resources/foo.py
  8. 0 0
      config.py
  9. 22 0
      manage.py
  10. 14 0
      requirements.txt

+ 6 - 0
.vscode/settings.json

@@ -0,0 +1,6 @@
+{
+    "python.pythonPath": "venv\\Scripts\\python.exe",
+    "python.linting.pylintEnabled": false,
+    "python.linting.pep8Enabled": true,
+    "python.linting.enabled": true
+}

+ 0 - 0
README.md


+ 8 - 0
app/__init__.py

@@ -0,0 +1,8 @@
+from flask_restful import Api
+from flask import Blueprint
+from app.main.resources.foo import Foo
+
+api_bp = Blueprint('api', __name__)
+api = Api(api_bp)
+
+api.add_resource(Foo, '/Foo')

+ 9 - 0
app/main/__init__.py

@@ -0,0 +1,9 @@
+from flask import Flask
+from app.main.config import config_by_name
+
+
+def create_app(config_name):
+    app = Flask(__name__)
+    app.config.from_object(config_by_name[config_name])
+
+    return app

+ 38 - 0
app/main/config.py

@@ -0,0 +1,38 @@
+import os
+
+BASE_DIR = os.path.abspath(os.path.dirname(__file__))
+
+class Config:
+    SECRET_KEY = os.getenv('SECRET_KEY', 'my_precious_secret_key')
+    DEBUG = False
+
+
+class DevelopmentConfig(Config):
+    # uncomment the line below to use postgres
+    # SQLALCHEMY_DATABASE_URI = postgres_local_base
+    DEBUG = True
+    # SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'flask_boilerplate_test.db')
+    # SQLALCHEMY_TRACK_MODIFICATIONS = False
+
+
+class TestingConfig(Config):
+    DEBUG = True
+    TESTING = True
+    # SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'flask_boilerplate_test.db')
+    PRESERVE_CONTEXT_ON_EXCEPTION = False
+    # SQLALCHEMY_TRACK_MODIFICATIONS = False
+
+
+class ProductionConfig(Config):
+    DEBUG = False
+    # uncomment the line below to use postgres
+    # SQLALCHEMY_DATABASE_URI = postgres_local_base
+
+
+config_by_name = dict(
+    dev=DevelopmentConfig,
+    test=TestingConfig,
+    prod=ProductionConfig
+)
+
+key = Config.SECRET_KEY

+ 0 - 0
app/main/resources/__init__.py


+ 6 - 0
app/main/resources/foo.py

@@ -0,0 +1,6 @@
+from flask_restful import Resource
+
+
+class Foo(Resource):
+    def get(self):
+        return {"message": "Hello, World!"}

+ 0 - 0
config.py


+ 22 - 0
manage.py

@@ -0,0 +1,22 @@
+import os
+from flask_script import Manager
+
+from app import api_bp
+from app.main import create_app
+
+
+app = create_app(os.getenv('BOILERPLATE_ENV') or 'dev')
+app.register_blueprint(api_bp, url_prefix='/api')
+
+app.app_context().push()
+
+manager = Manager(app)
+
+
+@manager.command
+def run():
+    app.run()
+
+
+if __name__ == '__main__':
+    manager.run()

+ 14 - 0
requirements.txt

@@ -0,0 +1,14 @@
+aniso8601==7.0.0
+APScheduler==3.6.1
+Click==7.0
+Flask==1.1.1
+Flask-Cors==3.0.8
+Flask-RESTful==0.3.7
+itsdangerous==1.1.0
+Jinja2==2.10.1
+MarkupSafe==1.1.1
+pep8==1.7.1
+pytz==2019.1
+six==1.12.0
+tzlocal==2.0.0
+Werkzeug==0.15.5