Skip to content

Commit

Permalink
[Base Revamp] Adds base revamp code
Browse files Browse the repository at this point in the history
  • Loading branch information
manrajgrover committed Apr 27, 2020
1 parent c6c044f commit 403f3bc
Show file tree
Hide file tree
Showing 115 changed files with 15,013 additions and 749 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ charset = utf-8
indent_style = space
indent_size = 4

[*.{js,html}]
[*.{js,html,yml}]
indent_style = space
indent_size = 2
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ dmypy.json
*.db

# vscode settings
*.json
./settings/*.json

# Sample files
!*.sample.json

# Flask
Expand Down
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"python.venvPath": "~/.virtualenvs",
"python.pythonPath": "/Users/manrajsingh/.virtualenvs/sat/bin/python",
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"python.linting.enabled": true,
"eslint.autoFixOnSave": true
}
10 changes: 6 additions & 4 deletions .vscode/settings.sample.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"python.venvPath": "~/.envs",
"python.pythonPath": "",
"python.formatting.provider": "black",
"python.linting.enabled": true
"python.venvPath": "~/.envs",
"python.pythonPath": "",
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"python.linting.enabled": true,
"eslint.autoFixOnSave": true
}
7 changes: 0 additions & 7 deletions Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions app.py

This file was deleted.

17 changes: 17 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
__pycache__
*.pyc
*.pyo
*.pyd
.Python
env
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.log
.git
2 changes: 1 addition & 1 deletion .flaskenv.sample → backend/.flaskenv.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FLASK_APP=app.py
FLASK_DEBUG=0
FLASK_ENV=production
DATABASE_URL=mysql+pymysql://<username>:<password>@<host>/<database>
SECRET_KEY=randomkeygoeshere
SQLALCHEMY_ECHO=False
7 changes: 7 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.7-alpine

COPY ./requirements.txt /app/backend

RUN pip install -r requirements.txt

COPY . /app/backend
52 changes: 52 additions & 0 deletions backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os

from flask import Flask, jsonify
from flask_jwt_extended import JWTManager
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from flask_redis import FlaskRedis
from werkzeug.exceptions import HTTPException, default_exceptions

from backend.config import Config


def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)

app.config.from_object(Config)

return app


app = create_app()

db = SQLAlchemy(app)
migrate = Migrate(app, db)
jwt = JWTManager(app)
redis_client = FlaskRedis(app)
# login = LoginManager(app)
# login.login_view = "routes.login"

from backend import models


def handle_error(error):
if isinstance(error, HTTPException):
return jsonify(message=error.description, code=error.code)
return jsonify(message="An error occured", code=500)


for exc in default_exceptions:
app.register_error_handler(exc, handle_error)


# @login.user_loader
# def load_user(id):
# return models.User.query.get(int(id))


from .routes import auth, api

app.register_blueprint(auth)
app.register_blueprint(api)
# app.add_template_global(name='version', f='1.0')
13 changes: 13 additions & 0 deletions backend/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from backend import app, db


@app.shell_context_processor
def make_shell_context():
return {"db": db, "app": app}


@app.teardown_request
def teardown_request(exception):
if exception:
db.session.rollback()
db.session.remove()
22 changes: 22 additions & 0 deletions backend/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

from datetime import timedelta

basedir = os.path.abspath(os.path.dirname(__file__))


class Config(object):
SECRET_KEY = os.environ.get("SECRET_KEY", None)
SQLALCHEMY_DATABASE_URI = os.environ.get(
"DATABASE_URL"
) or "sqlite:///" + os.path.join(basedir, "app.db")
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ECHO = True if os.environ.get("SQLALCHEMY_ECHO") == "True" else False
REDIS_URL = os.environ.get("JWT_REDIS_STORE_URL", "")
JWT_SECRET_KEY = os.environ.get("JWT_SECRET_KEY", "")
JWT_ACCESS_TOKEN_EXPIRES = os.environ.get(
"JWT_ACCESS_TOKEN_EXPIRES", timedelta(days=7)
)
JWT_BLACKLIST_ENABLED = True
JWT_HEADER_TYPE = None
JWT_BLACKLIST_TOKEN_CHECKS = ["access"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 403f3bc

Please sign in to comment.