Python flask.current_app.extensions() Examples
The following are 30
code examples of flask.current_app.extensions().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask.current_app
, or try the search function
.
Example #1
Source File: metadata_extensions.py From invenio-app-ils with MIT License | 6 votes |
def add_es_metadata_extensions(record_dict): """Add "extensions_X" fields to record_dict prior to Elasticsearch index. :param record_dict: dumped Record dict """ rec_type = record_dict["$schema"].split("/")[-1].split("-")[0] metadata_extensions = getattr( current_app.extensions["invenio-app-ils"], "{}_metadata_extensions".format(rec_type) ) for key, value in record_dict.get("extensions", {}).items(): field_type = metadata_extensions.get_field_type(key, "elasticsearch") if not field_type: continue es_field = "extensions_{}s".format(field_type) if es_field not in record_dict: record_dict[es_field] = [] record_dict[es_field].append({"key": key, "value": value})
Example #2
Source File: __init__.py From flask-jwt with MIT License | 6 votes |
def init_app(self, app): for k, v in CONFIG_DEFAULTS.items(): app.config.setdefault(k, v) app.config.setdefault('JWT_SECRET_KEY', app.config['SECRET_KEY']) auth_url_rule = app.config.get('JWT_AUTH_URL_RULE', None) if auth_url_rule: if self.auth_request_callback == _default_auth_request_handler: assert self.authentication_callback is not None, ( 'an authentication_handler function must be defined when using the built in ' 'authentication resource') auth_url_options = app.config.get('JWT_AUTH_URL_OPTIONS', {'methods': ['POST']}) auth_url_options.setdefault('view_func', self.auth_request_callback) app.add_url_rule(auth_url_rule, **auth_url_options) app.errorhandler(JWTError)(self._jwt_error_callback) if not hasattr(app, 'extensions'): # pragma: no cover app.extensions = {} app.extensions['jwt'] = self
Example #3
Source File: user_handler.py From cloudify-manager with Apache License 2.0 | 6 votes |
def get_token_status(token): """Mimic flask_security.utils.get_token_status with some changes :param token: The token to decrypt :return: A tuple: (expired, invalid, user, data) """ security = current_app.extensions['security'] serializer = security.remember_token_serializer max_age = security.token_max_age user, data, error = None, None, None expired, invalid = False, False try: data = serializer.loads(token, max_age=max_age) except SignatureExpired: expired = True except (BadSignature, TypeError, ValueError) as e: invalid = True error = e if data: user = user_datastore.find_user(id=data[0]) return expired, invalid, user, data, error
Example #4
Source File: mail_util.py From flask-security with MIT License | 6 votes |
def send_mail( self, template, subject, recipient, sender, body, html, user, **kwargs ): """Send an email via the Flask-Mail extension. :param template: the Template name. The message has already been rendered however this might be useful to differentiate why the email is being sent. :param subject: Email subject :param recipient: Email recipient :param sender: who to send email as (see :py:data:`SECURITY_EMAIL_SENDER`) :param body: the rendered body (text) :param html: the rendered body (html) :param user: the user model """ from flask_mail import Message msg = Message(subject, sender=sender, recipients=[recipient]) msg.body = body msg.html = html mail = current_app.extensions.get("mail") mail.send(msg)
Example #5
Source File: forms.py From flask-security with MIT License | 6 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if not self.next.data: self.next.data = request.args.get("next", "") self.remember.default = config_value("DEFAULT_REMEMBER_ME") if ( current_app.extensions["security"].recoverable and not self.password.description ): html = Markup( '<a href="{url}">{message}</a>'.format( url=url_for_security("forgot_password"), message=get_message("FORGOT_PASSWORD")[0], ) ) self.password.description = html
Example #6
Source File: env.py From flask-boilerplate with MIT License | 6 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ engine = engine_from_config(config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) connection = engine.connect() context.configure(connection=connection, target_metadata=target_metadata, **current_app.extensions['migrate'].configure_args) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()
Example #7
Source File: flask_moment.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def init_app(self, app): if not hasattr(app, 'extensions'): app.extensions = {} app.extensions['moment'] = _moment app.context_processor(self.context_processor)
Example #8
Source File: env.py From passhport with GNU Affero General Public License v3.0 | 5 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html def process_revision_directives(context, revision, directives): if getattr(config.cmd_opts, 'autogenerate', False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] logger.info('No changes in schema detected.') engine = engine_from_config(config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) connection = engine.connect() context.configure(connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, compare_type=True, **current_app.extensions['migrate'].configure_args) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()
Example #9
Source File: flask_moment.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def context_processor(): return { 'moment': current_app.extensions['moment'] }
Example #10
Source File: flask_moment.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def create(self, timestamp=None): return current_app.extensions['moment'](timestamp)
Example #11
Source File: __init__.py From Flask-Store with MIT License | 5 votes |
def init_app(self, app): """ Sets up application default confugration options and sets a ``Provider`` property which can be used to access the default provider class which handles the saving of files. Arguments --------- app : flask.app.Flask Flask application instance """ app.config.setdefault('STORE_DOMAIN', None) app.config.setdefault('STORE_PROVIDER', DEFAULT_PROVIDER) if not hasattr(app, 'extensions'): app.extensions = {} app.extensions['store'] = StoreState(self, app) # Set the provider class self.Provider = self.provider(app) # Set configuration defaults based on provider self.set_provider_defaults(app) # Ensure that any required configuration vars exist self.check_config(app) # Register a flask route - the provider must have register_route = True self.register_route(app)
Example #12
Source File: env.py From dataserv with MIT License | 5 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: http://alembic.readthedocs.org/en/latest/cookbook.html def process_revision_directives(context, revision, directives): if getattr(config.cmd_opts, 'autogenerate', False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] logger.info('No changes in schema detected.') engine = engine_from_config(config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) connection = engine.connect() context.configure(connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, **current_app.extensions['migrate'].configure_args) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()
Example #13
Source File: env.py From pade with MIT License | 5 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html def process_revision_directives(context, revision, directives): if getattr(config.cmd_opts, 'autogenerate', False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] logger.info('No changes in schema detected.') engine = engine_from_config(config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) connection = engine.connect() context.configure(connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, **current_app.extensions['migrate'].configure_args) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()
Example #14
Source File: env.py From cloudify-manager with Apache License 2.0 | 5 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: http://alembic.readthedocs.org/en/latest/cookbook.html def process_revision_directives(context, revision, directives): if getattr(config.cmd_opts, 'autogenerate', False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] logger.info('No changes in schema detected.') engine = engine_from_config(config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) connection = engine.connect() context.configure(connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, **current_app.extensions['migrate'].configure_args) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()
Example #15
Source File: __init__.py From Flask-Store with MIT License | 5 votes |
def store_provider(): """ Returns the default provider class as defined in the application configuration. Returns ------- class The provider class """ store = current_app.extensions['store'] return store.store.Provider
Example #16
Source File: flask.py From squealy with MIT License | 5 votes |
def __init__(self, resource_id=None, resource=None): if resource: self.resource = resource elif resource_id: squealy = current_app.extensions['squealy'] self.resource = squealy.get_resource(resource_id) else: self.resource = None
Example #17
Source File: flask.py From squealy with MIT License | 5 votes |
def get(self, *args, **kwargs): squealy = current_app.extensions['squealy'] if not self.resource: self.resource = squealy.get_resource(request.endpoint) context = self.build_context(request, *args, **kwargs) data = self.resource.process(squealy, context) return jsonify(data)
Example #18
Source File: env.py From DeepChatModels with MIT License | 5 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: http://alembic.readthedocs.org/en/latest/cookbook.html def process_revision_directives(context, revision, directives): if getattr(config.cmd_opts, 'autogenerate', False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] logger.info('No changes in schema detected.') engine = engine_from_config(config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) connection = engine.connect() context.configure(connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, **current_app.extensions['migrate'].configure_args) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()
Example #19
Source File: env.py From cookiecutter-flask-restful with MIT License | 5 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html def process_revision_directives(context, revision, directives): if getattr(config.cmd_opts, 'autogenerate', False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] logger.info('No changes in schema detected.') connectable = engine_from_config( config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool, ) with connectable.connect() as connection: context.configure( connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, **current_app.extensions['migrate'].configure_args ) with context.begin_transaction(): context.run_migrations()
Example #20
Source File: __init__.py From flask-smorest with MIT License | 5 votes |
def write_openapi_doc(output_file): """Write OpenAPI document to a file.""" api = current_app.extensions['flask-smorest']['ext_obj'] output_file.write(json.dumps(api.spec.to_dict(), indent=2))
Example #21
Source File: __init__.py From flask-smorest with MIT License | 5 votes |
def print_openapi_doc(): """Print OpenAPI document.""" api = current_app.extensions['flask-smorest']['ext_obj'] print(json.dumps(api.spec.to_dict(), indent=2))
Example #22
Source File: env.py From contentdb with GNU General Public License v3.0 | 5 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html def process_revision_directives(context, revision, directives): if getattr(config.cmd_opts, 'autogenerate', False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] logger.info('No changes in schema detected.') engine = engine_from_config(config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) connection = engine.connect() context.configure(connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, compare_type=True, **current_app.extensions['migrate'].configure_args) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()
Example #23
Source File: env.py From zou with GNU Affero General Public License v3.0 | 5 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html def process_revision_directives(context, revision, directives): if getattr(config.cmd_opts, 'autogenerate', False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] logger.info('No changes in schema detected.') engine = engine_from_config(config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) connection = engine.connect() context.configure(connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, render_item=render_item, compare_type=True, **current_app.extensions['migrate'].configure_args) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()
Example #24
Source File: env.py From Python24 with MIT License | 5 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html def process_revision_directives(context, revision, directives): if getattr(config.cmd_opts, 'autogenerate', False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] logger.info('No changes in schema detected.') connectable = engine_from_config( config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool, ) with connectable.connect() as connection: context.configure( connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, **current_app.extensions['migrate'].configure_args ) with context.begin_transaction(): context.run_migrations()
Example #25
Source File: api.py From babbage with MIT License | 5 votes |
def get_manager(): """ Try to locate a ``CubeManager`` on the Flask app which is currently processing a request. This will only work inside the request cycle. """ return current_app.extensions['babbage']
Example #26
Source File: api.py From babbage with MIT License | 5 votes |
def configure_api(app, manager): """ Configure the current Flask app with an instance of ``CubeManager`` that will be used to load and query data. """ if not hasattr(app, 'extensions'): app.extensions = {} # pragma: nocover app.extensions['babbage'] = manager return blueprint
Example #27
Source File: decorators.py From flask-security with MIT License | 5 votes |
def handle_csrf(method): """ Invoke CSRF protection based on authentication method. Usually this is called as part of a decorator, but if that isn't appropriate, endpoint code can call this directly. If CSRF protection is appropriate, this will call flask_wtf::protect() which will raise a ValidationError on CSRF failure. This routine does nothing if any of these are true: #) *WTF_CSRF_ENABLED* is set to False #) the Flask-WTF CSRF module hasn't been initialized #) csrfProtect already checked and accepted the token If the passed in method is not in *SECURITY_CSRF_PROTECT_MECHANISMS* then not only will no CSRF code be run, but a flag in the current context ``fs_ignore_csrf`` will be set so that downstream code knows to ignore any CSRF checks. .. versionadded:: 3.3.0 """ if ( not current_app.config.get("WTF_CSRF_ENABLED", False) or not current_app.extensions.get("csrf", None) or g.get("csrf_valid", False) ): return if config_value("CSRF_PROTECT_MECHANISMS"): if method in config_value("CSRF_PROTECT_MECHANISMS"): _csrf.protect() else: _request_ctx_stack.top.fs_ignore_csrf = True
Example #28
Source File: api.py From flask-security with MIT License | 5 votes |
def popmail(): # This gets and pops the most recently sent email # Please please do not do this in your real application! mailer = current_app.extensions["mail"] sent = mailer.pop() if sent: return jsonify(mail=sent) abort(400)
Example #29
Source File: env.py From arch-security-tracker with MIT License | 5 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html def process_revision_directives(context, revision, directives): if getattr(config.cmd_opts, 'autogenerate', False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] logger.info('No changes in schema detected.') engine = engine_from_config(config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) connection = engine.connect() context.configure(connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, render_as_batch=True, **current_app.extensions['migrate'].configure_args) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()
Example #30
Source File: env.py From website with MIT License | 5 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: https://alembic.readthedocs.io/en/latest/cookbook.html def process_revision_directives(context, revision, directives): if getattr(config.cmd_opts, "autogenerate", False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] logger.info("No changes in schema detected.") engine = engine_from_config( config.get_section(config.config_ini_section), prefix="sqlalchemy.", poolclass=pool.NullPool, ) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, **current_app.extensions["migrate"].configure_args ) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()