• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python connector_registry.ConnectorRegistry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中superset.connectors.connector_registry.ConnectorRegistry的典型用法代码示例。如果您正苦于以下问题:Python ConnectorRegistry类的具体用法?Python ConnectorRegistry怎么用?Python ConnectorRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ConnectorRegistry类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: import_obj

    def import_obj(cls, slc_to_import, import_time=None):
        """Inserts or overrides slc in the database.

        remote_id and import_time fields in params_dict are set to track the
        slice origin and ensure correct overrides for multiple imports.
        Slice.perm is used to find the datasources and connect them.
        """
        session = db.session
        make_transient(slc_to_import)
        slc_to_import.dashboards = []
        slc_to_import.alter_params(
            remote_id=slc_to_import.id, import_time=import_time)

        # find if the slice was already imported
        slc_to_override = None
        for slc in session.query(Slice).all():
            if ('remote_id' in slc.params_dict and
                    slc.params_dict['remote_id'] == slc_to_import.id):
                slc_to_override = slc

        slc_to_import = slc_to_import.copy()
        params = slc_to_import.params_dict
        slc_to_import.datasource_id = ConnectorRegistry.get_datasource_by_name(
            session, slc_to_import.datasource_type, params['datasource_name'],
            params['schema'], params['database_name']).id
        if slc_to_override:
            slc_to_override.override(slc_to_import)
            session.flush()
            return slc_to_override.id
        session.add(slc_to_import)
        logging.info('Final slice: {}'.format(slc_to_import.to_json()))
        session.flush()
        return slc_to_import.id
开发者ID:avsolatorio,项目名称:caravel,代码行数:33,代码来源:core.py


示例2: import_obj

    def import_obj(cls, slc_to_import, slc_to_override, import_time=None):
        """Inserts or overrides slc in the database.

        remote_id and import_time fields in params_dict are set to track the
        slice origin and ensure correct overrides for multiple imports.
        Slice.perm is used to find the datasources and connect them.

        :param Slice slc_to_import: Slice object to import
        :param Slice slc_to_override: Slice to replace, id matches remote_id
        :returns: The resulting id for the imported slice
        :rtype: int
        """
        session = db.session
        make_transient(slc_to_import)
        slc_to_import.dashboards = []
        slc_to_import.alter_params(
            remote_id=slc_to_import.id, import_time=import_time)

        slc_to_import = slc_to_import.copy()
        params = slc_to_import.params_dict
        slc_to_import.datasource_id = ConnectorRegistry.get_datasource_by_name(
            session, slc_to_import.datasource_type, params['datasource_name'],
            params['schema'], params['database_name']).id
        if slc_to_override:
            slc_to_override.override(slc_to_import)
            session.flush()
            return slc_to_override.id
        session.add(slc_to_import)
        logging.info('Final slice: {}'.format(slc_to_import.to_json()))
        session.flush()
        return slc_to_import.id
开发者ID:neuroradiology,项目名称:caravel,代码行数:31,代码来源:core.py


示例3: create_missing_perms

def create_missing_perms():
    """Creates missing perms for datasources, schemas and metrics"""

    logging.info(
        "Fetching a set of all perms to lookup which ones are missing")
    all_pvs = set()
    for pv in sm.get_session.query(sm.permissionview_model).all():
        if pv.permission and pv.view_menu:
            all_pvs.add((pv.permission.name, pv.view_menu.name))

    def merge_pv(view_menu, perm):
        """Create permission view menu only if it doesn't exist"""
        if view_menu and perm and (view_menu, perm) not in all_pvs:
            merge_perm(sm, view_menu, perm)

    logging.info("Creating missing datasource permissions.")
    datasources = ConnectorRegistry.get_all_datasources(db.session)
    for datasource in datasources:
        merge_pv('datasource_access', datasource.get_perm())
        merge_pv('schema_access', datasource.schema_perm)

    logging.info("Creating missing database permissions.")
    databases = db.session.query(models.Database).all()
    for database in databases:
        merge_pv('database_access', database.perm)

    logging.info("Creating missing metrics permissions")
    metrics = []
    for datasource_class in ConnectorRegistry.sources.values():
        metrics += list(db.session.query(datasource_class.metric_class).all())

    for metric in metrics:
        if (metric.is_restricted):
            merge_pv('metric_access', metric.perm)
开发者ID:invenis-paris,项目名称:incubator-superset,代码行数:34,代码来源:security.py


示例4: create_missing_datasource_perms

def create_missing_datasource_perms(view_menu_set):
    logging.info("Creating missing datasource permissions.")
    datasources = ConnectorRegistry.get_all_datasources(
        db.session)
    for datasource in datasources:
        if datasource and datasource.perm not in view_menu_set:
            merge_perm(sm, 'datasource_access', datasource.get_perm())
            if datasource.schema_perm:
                merge_perm(sm, 'schema_access', datasource.schema_perm)
开发者ID:avsolatorio,项目名称:caravel,代码行数:9,代码来源:security.py


示例5: __init__

 def __init__(
         self,
         datasource: Dict,
         queries: List[Dict],
 ):
     self.datasource = ConnectorRegistry.get_datasource(datasource.get('type'),
                                                        int(datasource.get('id')),
                                                        db.session)
     self.queries = list(map(lambda query_obj: QueryObject(**query_obj), queries))
开发者ID:bkyryliuk,项目名称:caravel,代码行数:9,代码来源:query_context.py


示例6: datasource_access_by_name

    def datasource_access_by_name(
            self, database, datasource_name, schema=None):
        if self.database_access(database) or self.all_datasource_access():
            return True

        schema_perm = utils.get_schema_perm(database, schema)
        if schema and self.can_access('schema_access', schema_perm):
            return True

        datasources = ConnectorRegistry.query_datasources_by_name(
            db.session, database, datasource_name, schema=schema)
        for datasource in datasources:
            if self.can_access('datasource_access', datasource.perm):
                return True
        return False
开发者ID:herotan24,项目名称:incubator-superset,代码行数:15,代码来源:base.py


示例7: __init__

    def __init__(
            self,
            datasource: Dict,
            queries: List[Dict],
            force: bool = False,
            custom_cache_timeout: int = None,
    ):
        self.datasource = ConnectorRegistry.get_datasource(datasource.get('type'),
                                                           int(datasource.get('id')),
                                                           db.session)
        self.queries = list(map(lambda query_obj: QueryObject(**query_obj), queries))

        self.force = force

        self.custom_cache_timeout = custom_cache_timeout

        self.enforce_numerical_metrics = True
开发者ID:neuroradiology,项目名称:caravel,代码行数:17,代码来源:query_context.py


示例8: save

    def save(self):
        datasource = json.loads(request.form.get('data'))
        datasource_id = datasource.get('id')
        datasource_type = datasource.get('type')
        orm_datasource = ConnectorRegistry.get_datasource(
            datasource_type, datasource_id, db.session)

        if not check_ownership(orm_datasource, raise_if_false=False):
            return json_error_response(
                __(
                    'You are not authorized to modify '
                    'this data source configuration'),
                status='401',
            )
        orm_datasource.update_from_object(datasource)
        data = orm_datasource.data
        db.session.commit()
        return self.json_response(data)
开发者ID:chenhaiyan,项目名称:incubator-superset,代码行数:18,代码来源:datasource.py


示例9: accessible_by_user

    def accessible_by_user(self, database, datasource_names, schema=None):
        if self.database_access(database) or self.all_datasource_access():
            return datasource_names

        if schema:
            schema_perm = utils.get_schema_perm(database, schema)
            if self.can_access('schema_access', schema_perm):
                return datasource_names

        user_perms = self.user_datasource_perms()
        user_datasources = ConnectorRegistry.query_datasources_by_permissions(
            db.session, database, user_perms)
        if schema:
            names = {
                d.table_name
                for d in user_datasources if d.schema == schema}
            return [d for d in datasource_names if d in names]
        else:
            full_names = {d.full_name for d in user_datasources}
            return [d for d in datasource_names if d in full_names]
开发者ID:herotan24,项目名称:incubator-superset,代码行数:20,代码来源:base.py


示例10: export_dashboards

    def export_dashboards(cls, dashboard_ids):
        copied_dashboards = []
        datasource_ids = set()
        for dashboard_id in dashboard_ids:
            # make sure that dashboard_id is an integer
            dashboard_id = int(dashboard_id)
            copied_dashboard = (
                db.session.query(Dashboard)
                .options(subqueryload(Dashboard.slices))
                .filter_by(id=dashboard_id).first()
            )
            make_transient(copied_dashboard)
            for slc in copied_dashboard.slices:
                datasource_ids.add((slc.datasource_id, slc.datasource_type))
                # add extra params for the import
                slc.alter_params(
                    remote_id=slc.id,
                    datasource_name=slc.datasource.name,
                    schema=slc.datasource.name,
                    database_name=slc.datasource.database.name,
                )
            copied_dashboard.alter_params(remote_id=dashboard_id)
            copied_dashboards.append(copied_dashboard)

            eager_datasources = []
            for dashboard_id, dashboard_type in datasource_ids:
                eager_datasource = ConnectorRegistry.get_eager_datasource(
                    db.session, dashboard_type, dashboard_id)
                eager_datasource.alter_params(
                    remote_id=eager_datasource.id,
                    database_name=eager_datasource.database.name,
                )
                make_transient(eager_datasource)
                eager_datasources.append(eager_datasource)

        return json.dumps({
            'dashboards': copied_dashboards,
            'datasources': eager_datasources,
        }, cls=utils.DashboardEncoder, indent=4)
开发者ID:neuroradiology,项目名称:caravel,代码行数:39,代码来源:core.py


示例11: accessible_by_user

    def accessible_by_user(self, database, datasource_names, schema=None):
        if self.database_access(database) or self.all_datasource_access():
            return datasource_names

        schema_perm = utils.get_schema_perm(database, schema)
        if schema and utils.can_access(
                sm, 'schema_access', schema_perm, g.user):
            return datasource_names

        role_ids = set([role.id for role in g.user.roles])
        # TODO: cache user_perms or user_datasources
        user_pvms = (
            db.session.query(ab_models.PermissionView)
            .join(ab_models.Permission)
            .filter(ab_models.Permission.name == 'datasource_access')
            .filter(ab_models.PermissionView.role.any(
                ab_models.Role.id.in_(role_ids)))
            .all()
        )
        user_perms = set([pvm.view_menu.name for pvm in user_pvms])
        user_datasources = ConnectorRegistry.query_datasources_by_permissions(
            db.session, database, user_perms)
        full_names = set([d.full_name for d in user_datasources])
        return [d for d in datasource_names if d in full_names]
开发者ID:dawsongzhao,项目名称:superset,代码行数:24,代码来源:base.py


示例12: get_viz

def get_viz(
        slice_id=None,
        form_data=None,
        datasource_type=None,
        datasource_id=None,
        force=False,
):
    if slice_id:
        slc = (
            db.session.query(models.Slice)
            .filter_by(id=slice_id)
            .one()
        )
        return slc.get_viz()
    else:
        viz_type = form_data.get('viz_type', 'table')
        datasource = ConnectorRegistry.get_datasource(
            datasource_type, datasource_id, db.session)
        viz_obj = viz.viz_types[viz_type](
            datasource,
            form_data=form_data,
            force=force,
        )
        return viz_obj
开发者ID:tan31989,项目名称:caravel,代码行数:24,代码来源:utils.py


示例13: middleware

        pass

for middleware in app.config.get('ADDITIONAL_MIDDLEWARE'):
    app.wsgi_app = middleware(app.wsgi_app)


class MyIndexView(IndexView):
    @expose('/')
    def index(self):
        return redirect('/superset/welcome')


appbuilder = AppBuilder(
    app,
    db.session,
    base_template='superset/base.html',
    indexview=MyIndexView,
    security_manager_class=app.config.get("CUSTOM_SECURITY_MANAGER"))

sm = appbuilder.sm

get_session = appbuilder.get_session
results_backend = app.config.get("RESULTS_BACKEND")

# Registering sources
module_datasource_map = app.config.get("DEFAULT_MODULE_DS_MAP")
module_datasource_map.update(app.config.get("ADDITIONAL_MODULE_DS_MAP"))
ConnectorRegistry.register_sources(module_datasource_map)

from superset import views  # noqa
开发者ID:rahulsingh303,项目名称:incubator-superset,代码行数:30,代码来源:__init__.py


示例14: external_metadata

 def external_metadata(self, datasource_type=None, datasource_id=None):
     """Gets column info from the source system"""
     orm_datasource = ConnectorRegistry.get_datasource(
         datasource_type, datasource_id, db.session)
     return self.json_response(orm_datasource.external_metadata())
开发者ID:bkyryliuk,项目名称:caravel,代码行数:5,代码来源:datasource.py



注:本文中的superset.connectors.connector_registry.ConnectorRegistry类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.DruidDatasource类代码示例发布时间:2022-05-27
下一篇:
Python conf.get函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap