60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
from flask import Flask, session, url_for, escape, request, send_file, abort
|
|
from settings import config
|
|
from importlib import import_module
|
|
import os
|
|
import sys
|
|
import inspect
|
|
|
|
def start_app():
|
|
|
|
app=Flask(__name__, static_url_path=config.static_url_path, static_folder=config.static_folder)
|
|
|
|
app.secret_key=config.secret_key
|
|
|
|
application_root='/'
|
|
|
|
if hasattr(config, 'application_root'):
|
|
application_root=config.application_root
|
|
|
|
|
|
app.config.update(
|
|
APPLICATION_ROOT=application_root
|
|
)
|
|
|
|
workdir=os.getcwd()
|
|
arr_module_path={}
|
|
|
|
# Load blueprints
|
|
|
|
for added_app in config.apps:
|
|
|
|
module_app=config.apps[added_app][0]
|
|
|
|
a=import_module(module_app)
|
|
#print(added_app, file=sys.stdout)
|
|
app_name=getattr(a, config.apps[added_app][1])
|
|
|
|
app.register_blueprint(app_name, url_prefix=config.apps[added_app][2])
|
|
|
|
arr_module_path[added_app]=os.path.dirname(sys.modules[module_app].__file__)
|
|
|
|
#Add media files support. Only for development.
|
|
|
|
#print(inspect.getmembers(sys.modules['paramecio2.modules.admin.app']))
|
|
#print(os.path.dirname(sys.modules['paramecio2.modules.admin.app'].__file__))
|
|
|
|
@app.route('/mediafrom/<module>/<path:media_file>')
|
|
def send_media_file(module, media_file):
|
|
|
|
file_path=workdir+'/themes/'+config.theme+'/media/'+module+'/'+media_file
|
|
|
|
if not os.path.isfile(file_path):
|
|
#file_path=workdir+'/modules/'+module+'/media/'+media_file
|
|
file_path=arr_module_path[module]+'/media/'+media_file
|
|
|
|
if not os.path.isfile(file_path):
|
|
abort(404)
|
|
|
|
return send_file(file_path)
|
|
|
|
return app
|