Example #1
0
# Configure from the environment, global (immutable) variables (before submodules import)


class Config(object):
    SECRET_KEY = environ["SECRET_KEY"]
    SENDGRID_USERNAME = environ["SENDGRID_USERNAME"]
    SENDGRID_PASSWORD = environ["SENDGRID_PASSWORD"]
    MONGO_URI = environ["MONGOLAB_URI"]


# Create the app and mongo helper
app = Flask(__name__)

app.config["MONGO_URI"] = Config.MONGO_URI
app.config[
    "MONGO_CONNECT"
] = "False"  # http://api.mongodb.org/python/current/faq.html#using-pymongo-with-multiprocessing
mongo = PyMongo(app)

from .api import api
from .helpers import query_from_dict
from .tags import tags
from .json import NofussbmJSONEncoder, NofussbmJSONDecoder

app.json_encoder = NofussbmJSONEncoder
app.json_decoder = NofussbmJSONDecoder

# Register APIs blueprint and setup {before,teardown}_request

app.register_blueprint(api, url_prefix="/api/v1")
Example #2
0
console_format = logging.Formatter(" %(asctime)s %(levelname)s: %(message)s [in %(module)s:%(lineno)d]")
console_logger.setFormatter(console_format)
console_logger.setLevel(logging.WARNING)
app.logger.addHandler(console_logger)


if os.environ.get("EXTERNAL"):
    app.config["MONGO_URI"] = os.environ["MONGO_URI"]
    app.config["MONGO_CONNECT"] = False
    app.secret_key = os.environ["random_key"]
    app.config["BROKER_URL"] = os.environ["REDIS_URL"]  # Celery
    app.config["CELERY_RESULT_BACKEND"] = os.environ["REDIS_URL"]
else:
    with open("../Other-Secrets/TITDev.json") as secrets_file:
        secrets = json.load(secrets_file)
    app.config["MONGO_HOST"] = secrets["mongo-host"]
    app.config["MONGO_DBNAME"] = secrets["mongo-db"]
    app.config["MONGO_USERNAME"] = secrets["mongo-user"]
    app.config["MONGO_PASSWORD"] = secrets["mongo-password"]
    app.config["MONGO_PORT"] = secrets["mongo-port"]
    app.config["BROKER_URL"] = secrets["redis-host"]  # Celery
    app.config["CELERY_RESULT_BACKEND"] = secrets["redis-host"]
    app.config["MONGO_CONNECT"] = False
    app.secret_key = secrets["random_key"]

Bootstrap(app)
cdn_theme_url = "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.5/slate/"
app.extensions["bootstrap"]["cdns"]["theme"] = WebCDN(cdn_theme_url)  # CDN Theme
app_mongo = PyMongo(app)

# Redis