def init_app(): # we still need those global varibales during request import os import api import json import mimetypes import common.error current_app.before_request(init_global_variables) @current_app.errorhandler(common.error.ApiError) def error_handler(error): return json.dumps(error.data), 400 @current_app.route('/', defaults={'filename': 'index'}) @current_app.route('/<filename>') def send_static_files(filename): if not os.path.splitext(filename)[1]: filename += ".html" resp = current_app.send_static_file(filename) resp.mimetype = mimetypes.guess_type(filename)[0] return resp current_app.register_blueprint(api.get_blueprint(), url_prefix="/api")
def init_app(): # 初始化app # we still need those global variables during request import os import api import json import mimetypes import common.error current_app.before_request(init_global_variables) @current_app.errorhandler(common.error.ApiError) def error_handler(error): return json.dumps(error.data), 400 @current_app.route('/', defaults={'filename': 'home'}) @current_app.route('/<path:filename>') def send_static_files(filename): if os.path.isfile(os.path.join('static', filename)): pass if os.path.isfile(os.path.join('static', filename + '.html')): filename += '.html' if os.path.isfile(os.path.join('static', filename, 'pre.html')): filename += "/pre.html" resp = current_app.send_static_file(filename) resp.mimetype = mimetypes.guess_type(filename)[0] return resp current_app.register_blueprint(api.get_blueprint(), url_prefix="/api")
def init_config(): """ Initial configuration for the current app. Triggered the first time a resource is initialized. """ global APP_CONFIGURED if not APP_CONFIGURED: # Rate limiting setup if current_app.config['RATE_LIMITING_ACTIVE']: rate_limit = current_app.config['GLOBAL_RATE_LIMITS'] log.info('Rate limiting active: %s' % rate_limit) else: log.info('Rate limiting is off') # Caching setup if current_app.config['CACHING_ACTIVE']: log.info('Caching is active') else: current_app.config['CACHE_TYPE'] = 'null' log.info('Caching is off') current_app.config['CACHE_NO_NULL_WARNING'] = True # Register the cache instance and binds it on to your app if getattr(current_app, 'cache', None) is None: current_app.cache = Cache(current_app) current_app.cache.clear() current_app.before_request(on_request_start) APP_CONFIGURED = True
def init(self): super().init() current_app.before_request(self._before_request) self.connect(signals.plugin.cli, self._extend_indico_cli) self.connect(signals.plugin.get_template_customization_paths, self._override_templates) self.connect(signals.plugin.schema_post_dump, self._inject_long_term_attribute, sender=RoomSchema) self.connect(signals.plugin.schema_pre_load, self._inject_reason, sender=CreateBookingSchema) self.connect(signals.plugin.schema_pre_load, self._inject_time) self.inject_bundle('burotel.js', WPBurotelBase) self.inject_bundle('burotel.css', WPBurotelBase)
def init(self): super(ShowersPlugin, self).init() current_app.before_request(self._before_request) self.inject_bundle('react.js', WPShowersBase) self.inject_bundle('react.css', WPShowersBase) self.inject_bundle('semantic-ui.js', WPShowersBase) self.inject_bundle('semantic-ui.css', WPShowersBase) self.inject_bundle('showers.js', WPShowersBase) self.inject_bundle('showers.css', WPShowersBase) self.connect(signals.plugin.cli, self._extend_indico_cli)
def configure(app): app.add_url_rule('/', view_func=Base.as_view('index')) app.add_url_rule('/erase', view_func=EraseData.as_view('erase')) app.add_url_rule('/status', view_func=ImportStatus.as_view('import_status')) app.add_url_rule('/dataloader', view_func=DataLoader.as_view('data_loader')) app.add_url_rule('/upload', view_func=Upload.as_view('file_upload')) app.add_url_rule('/download', view_func=DownloadUrl.as_view('file_download')) app.add_url_rule('/copy', view_func=CopyFromData.as_view('copy_from_data')) app.add_url_rule('/start', view_func=StartImport.as_view('import_start')) app.before_request(before_request)
def protect_all_views(exclude=None): exclude = exclude or [] def _protect_all_views(): if request.endpoint not in exclude: if not is_authenticated(): return redirect(url_for('login')) _protect_all_views = current_app.before_request(_protect_all_views)
def init(self): super(BurotelPlugin, self).init() current_app.before_request(self._before_request)