def build_app(app): app.register_blueprint(auth_bundle) app.register_blueprint(home_bundle) app.register_blueprint(api_bundle) app.register_blueprint(profile_bundle) app.register_blueprint(content_bundle) app.register_blueprint(search_bundle) # Config to Flask from objects # app.config.from_object('fedora_college.core.ProductionConfig') app.config.from_object('fedora_college.core.config.DevelopmentConfig') db.init_app(app) # FAS OpenID Instance with app.app_context(): whooshalchemy.whoosh_index(app, Content) whooshalchemy.whoosh_index(app, Media) DebugToolbarExtension(app) admin = Admin(app, 'Auth', index_view=FedoraAdminIndexView()) admin.add_view(FedoraModelView(UserProfile, db.session)) admin.add_view(FedoraModelView(Content, db.session)) admin.add_view(FedoraModelView(Media, db.session)) admin.add_view(FedoraModelView(Tags, db.session)) admin.add_view( FedoraFileView(current_app.config['STATIC_FOLDER'], name='Static Files')) current_app.config['fas'] = FAS(app)
def build_app(app): app.register_blueprint(auth_bundle) app.register_blueprint(home_bundle) # Config to Flask from objects #app.config.from_object('fedora_college.core.ProductionConfig') app.config.from_object('fedora_college.core.config.DevelopmentConfig') # FAS OpenID Instance with app.app_context(): current_app.config['fas'] = FAS(app)
MAIL_HANDLER.setLevel(logging.ERROR) if not APP.debug: APP.logger.addHandler(MAIL_HANDLER) # Log to stderr as well STDERR_LOG = logging.StreamHandler(sys.stderr) STDERR_LOG.setLevel(logging.INFO) APP.logger.addHandler(STDERR_LOG) LOG = APP.logger if APP.config.get('MM_AUTHENTICATION') == 'fas': # Use FAS for authentication try: from flask_fas_openid import FAS FAS = FAS(APP) except ImportError: APP.logger.exception("Couldn't import flask-fas-openid") import mirrormanager2 import mirrormanager2.lib as mmlib import mirrormanager2.forms as forms import mirrormanager2.login_forms as login_forms import mirrormanager2.lib.model as model SESSION = mmlib.create_session(APP.config['DB_URL']) def is_mirrormanager_admin(user): """ Is the user a mirrormanager admin. """
from bs4 import BeautifulSoup from flask import Flask, render_template, request, url_for, session, redirect from flask import abort from flask_fas_openid import fas_login_required, FAS from util import RegexConverter, map_name_aliases, get_arrow_dates fn_search_regex = "(.*?)\.([0-9]{4}\-[0-9]{2}\-[0-9]{2})\-.*?\..*?\.(.*)" import config __version__ = "0.0.0" user_sessions = dict() app = Flask("mote") fas = FAS(app) app.secret_key = ''.join(random.SystemRandom().choice(string.uppercase + string.digits) for _ in xrange(20)) app.config['FAS_OPENID_ENDPOINT'] = 'http://id.fedoraproject.org/' app.config['FAS_CHECK_CERT'] = True cwd = os.getcwd() app.url_map.converters['regex'] = RegexConverter if config.use_mappings_github == True: name_mappings = requests.get( "https://raw.githubusercontent.com/fedora-infra/mote/master/name_mappings.json" ).text category_mappings = requests.get( "https://raw.githubusercontent.com/fedora-infra/mote/master/category_mappings.json" ).text
# https://github.com/miguelgrinberg/Flask-Migrate/issues/61#issuecomment-208131722 metadata = MetaData( naming_convention={ 'ix': 'ix_%(column_0_label)s', # index 'uq': 'uq_%(table_name)s_%(column_0_name)s', # unique 'ck': 'ck_%(table_name)s_%(column_0_name)s', # check 'fk': 'fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s', # foreign key 'pk': 'pk_%(table_name)s' # primary key }) bootstrap = Bootstrap() mail = Mail() moment = Moment() db = SQLAlchemy(metadata=metadata) ma = Marshmallow() pagedown = PageDown() oauth = OAuth() fas = FAS(Flask(__name__)) babel = Babel() cache = Cache() cache_control = FlaskCacheControl() compress = Compress() qrcode = QRcode() login_manager = LoginManager() login_manager.session_protection = 'strong' # 会话安全等级 login_manager.login_view = 'auth.login' # 登陆页endpoint login_manager.login_message = lazy_gettext( 'Please log in to access this page.') # 惰性求值