Flask application initialization.

        :param app: The Flask application.
        :param entry_point_group: Name of entry point group to load
            views/models from. (Default: ``'invenio_admin.views'``)
        :param permission_factory: Default permission factory to use when
            protecting an admin view. (Default:
            :func:`~.permissions.admin_permission_factory`)
        :param view_class_factory: Factory for creating admin view classes on
            the fly. Used to protect admin views with authentication and
            authorization. (Default:
            :func:`~.views.protected_adminview_factory`)
        :param index_view_class: Specify administrative interface index page.
            (Default: :class:`flask_admin.base.AdminIndexView`)
        :param kwargs: Passed to :class:`flask_admin.base.Admin`.
        :returns: Extension state.

def init_app(self,
                 app,
                 entry_point_group='invenio_admin.views',
                 permission_factory=None,
                 view_class_factory=protected_adminview_factory,
                 index_view_class=AdminIndexView):
        """Flask application initialization.

        :param app: The Flask application.
        :param entry_point_group: Name of entry point group to load
            views/models from. (Default: ``'invenio_admin.views'``)
        :param permission_factory: Default permission factory to use when
            protecting an admin view. (Default:
            :func:`~.permissions.admin_permission_factory`)
        :param view_class_factory: Factory for creating admin view classes on
            the fly. Used to protect admin views with authentication and
            authorization. (Default:
            :func:`~.views.protected_adminview_factory`)
        :param index_view_class: Specify administrative interface index page.
            (Default: :class:`flask_admin.base.AdminIndexView`)
        :param kwargs: Passed to :class:`flask_admin.base.Admin`.
        :returns: Extension state.
        """
        self.init_config(app)

        default_permission_factory = app.config['ADMIN_PERMISSION_FACTORY']
        permission_factory = permission_factory or \
            import_string(default_permission_factory)

        # Create administration app.

        admin = Admin(
            app,
            name=app.config['ADMIN_APPNAME'],
            template_mode=app.config['ADMIN_TEMPLATE_MODE'],
            index_view=view_class_factory(index_view_class)(),
        )

        @app.before_first_request
        def lazy_base_template():
            """Initialize admin base template lazily."""
            base_template = app.config.get('ADMIN_BASE_TEMPLATE')
            if base_template:
                admin.base_template = base_template

        # Create admin state
        state = _AdminState(app, admin, permission_factory, view_class_factory)
        if entry_point_group:
            state.load_entry_point_group(entry_point_group)

        app.extensions['invenio-admin'] = state
        return state