def __init__(self, old_file_name=None): if old_file_name: self._ext = old_file_name.rsplit('.', 1)[1].lower() self._old_file_name = old_file_name self._storage_path = os.path.join(current_app.root_path, 'storage') self._system = read_ini_file('system') try: self._img = Image.open( os.path.join(self._storage_path, old_file_name)) except IOError: raise Fail(message="图片不能打开")
def update_config(app): mail = read_ini_file('mail') tls = True if mail['link_model'] == 'tls' else False ssl = True if mail['link_model'] == 'ssl' else False app.config.update( MAIL_SERVER=mail['mail_server'], MAIL_PORT=int(mail['port']), MAIL_USERNAME=mail['username'], MAIL_PASSWORD=mail['password'], MAIL_USE_TLS=tls, MAIL_USE_SSL=ssl, )
def make_celery(app): system = read_ini_file('system', app.root_path) celery = Celery(app.import_name, backend=system['celery_broker_url'], broker=system['celery_result_backend']) celery.conf.update(app.config) TaskBase = celery.Task class ContextTask(TaskBase): abstract = True def __call__(self, *args, **kwargs): with app.app_context(): return TaskBase.__call__(self, *args, **kwargs) celery.Task = ContextTask return celery
""" created by hzwlxy at 2018/7/4 11:33 __author__: 西瓜哥 __QQ__ : 120235331 __Note__: 蓝图,模块分类 """ from flask import Blueprint, render_template, current_app from flask_wtf.csrf import CSRFError __author__ = '西瓜哥' from app.libs.layui_response import Fail from app.libs.helper import read_ini_file from app.libs.auth import Auth system = read_ini_file('system') admin_app = Blueprint('admin', __name__, url_prefix="/" + system['admin_prefix']) user_app = Blueprint('user', __name__, url_prefix="/user") upload_app = Blueprint('upload', __name__, url_prefix="/uploads") web_app = Blueprint('web', __name__) # errorhandler 是对于蓝图起作用的, app_errorhandler 是对于全局的异常处理,随便用哪个蓝图定义都行 @admin_app.app_errorhandler(CSRFError) def csrf_error(e): return Fail(message="CsrfToken错误,请刷新页面重试") # 后台 @admin_app.before_request def process_request():
""" created by hzwlxy at 2018/7/27 13:54 __author__: 西瓜哥 __QQ__ : 120235331 __Note__: """ __author__ = '西瓜哥' from app.libs.helper import read_ini_file config = read_ini_file(field="database") class Config: DEBUG = False SECRET_KEY = 'k9kcOdx8r8ei&7k@Z$rCay^ik!OuhhqFbr4fJ7MXaHWBomk#m2Zgm5mGisX@' SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_COMMIT_ON_TEARDOWN = True TEMPLATES_AUTO_RELOAD = True class ProductionConfig(Config): DEBUG = False TEMPLATES_AUTO_RELOAD = False SQLALCHEMY_DATABASE_URI = "{dbtype}://{username}:{password}@{host}:{port}/{dbname}".format( dbtype=config['DB_CONNECTION'], username=config['DB_USERNAME'], password=config['DB_PASSWORD'], host=config['DB_HOST'], port=config['DB_PORT'], dbname=config['DB_DATABASE'])
def __init__(self, config_path): self.__config_path = config_path self.__system = read_ini_file('system')
def __init__(self, upload_type="images", water=False, file_field="file"): self._type = upload_type self._water = water self._system = read_ini_file('system') self._uuid = str(uuid4()) self._file_field = file_field