1
1
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yadc/yadc/__init__.py

87 lines
2.5 KiB
Python

import os
import shutil
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_assets import Environment as AssetsEnvironment, Bundle as AssetsBundle
db = SQLAlchemy()
migrate = Migrate()
login = LoginManager()
assets = AssetsEnvironment()
def create_app():
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(POST_UPLOADS=os.path.join(app.instance_path, 'post'), SQLALCHEMY_TRACK_MODIFICATIONS=False)
# try:
# os.makedirs(app.instance_path)
# # os.makedirs(app.config.get('POST_UPLOADS'))
# for d in ['img', 'jpeg', 'sample', 'thumb']:
# os.makedirs(os.path.join(app.config.get('POST_UPLOADS'), d))
# # shutil.copyfile(os.path.join(app.root_path, 'config.def.py'), os.path.join(app.instance_path, 'config.py'))
# except OSError:
# pass
## TO REDO
app.config.from_pyfile('config.py')
db.init_app(app)
migrate.init_app(app, db)
login.init_app(app)
assets.init_app(app)
from yadc.bp import main, post, auth, manage, user
app.register_blueprint(main.bp)
app.register_blueprint(post.bp, url_prefix='/post')
app.register_blueprint(auth.bp, url_prefix='/auth')
app.register_blueprint(manage.bp, url_prefix='/manage')
app.register_blueprint(user.bp, url_prefix='/user')
login.login_view = 'auth.login'
from yadc import utils
@app.context_processor
def utility_processor():
return dict(utils=utils)
with app.app_context():
assets.append_path(os.path.join(app.root_path, 'assets'))
assets.append_path(os.path.join(app.root_path, 'assets/css'))
assets.append_path(os.path.join(app.root_path, 'assets/js'))
# print(assets.load_path)
#assets.url = app.static_url_path
scss = AssetsBundle(
'main.scss',
depends=('*.scss'), filters=['libsass','cssmin'], output='all.css')
assets.register('scss_all', scss)
js = AssetsBundle(
'formswitchers.js', 'base.js',
'taginput.js',
# filters='rjsmin',
output='all.js')
assets.register('js_all', js)
return app
from yadc import models as m
app = create_app()
@app.shell_context_processor
def make_shell_context():
ctxt = {'db': db}
for mdl in [m.User, m.Post, m.Tag, m.Comment]:
ctxt[mdl.__name__] = mdl
return ctxt
# return {'db': db, 'User': models.User, 'Post': models.Post, 'Tag': models.Tag, 'Comment': models.Comment}