当前位置: 首页>>代码示例>>Python>>正文


Python StaticDataSourceConfiguration.all方法代码示例

本文整理汇总了Python中corehq.apps.userreports.models.StaticDataSourceConfiguration.all方法的典型用法代码示例。如果您正苦于以下问题:Python StaticDataSourceConfiguration.all方法的具体用法?Python StaticDataSourceConfiguration.all怎么用?Python StaticDataSourceConfiguration.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在corehq.apps.userreports.models.StaticDataSourceConfiguration的用法示例。


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

示例1: handle

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import all [as 别名]
    def handle(self, **options):
        data_sources = list(DataSourceConfiguration.all())
        data_sources.extend(list(StaticDataSourceConfiguration.all()))

        engine_ids = self._get_engine_ids(data_sources, options.get('engine_id'))

        tables_to_remove_by_engine = defaultdict(list)
        for engine_id in engine_ids:
            engine = connection_manager.get_engine(engine_id)
            with engine.begin() as connection:
                migration_context = get_migration_context(connection, include_object=_include_object)
                raw_diffs = compare_metadata(migration_context, metadata)

            diffs = reformat_alembic_diffs(raw_diffs)
            tables_to_remove_by_engine[engine_id] = [
                diff.table_name for diff in diffs
                if diff.type == 'remove_table'
            ]

        for engine_id, tablenames in tables_to_remove_by_engine.items():
            engine = connection_manager.get_engine(engine_id)
            for tablename in tablenames:
                with engine.begin() as connection:
                    try:
                        result = connection.execute(
                            'SELECT COUNT(*), MAX(inserted_at) FROM "{tablename}"'.format(tablename=tablename)
                        )
                    except Exception:
                        print(tablename, "no inserted_at column, probably not UCR")
                    else:
                        print(tablename, result.fetchone())
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:33,代码来源:prune_old_datasources.py

示例2: test_get_all

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import all [as 别名]
 def test_get_all(self):
     with override_settings(STATIC_DATA_SOURCES=[self.get_path('sample_static_data_source', 'json')]):
         all = list(StaticDataSourceConfiguration.all())
         self.assertEqual(2, len(all))
         example, dimagi = all
         self.assertEqual('example', example.domain)
         self.assertEqual('dimagi', dimagi.domain)
         for config in all:
             self.assertEqual('all_candidates', config.table_id)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:11,代码来源:test_static_data_sources.py

示例3: _data_sources_by_engine_id

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import all [as 别名]
def _data_sources_by_engine_id():
    by_engine_id = defaultdict(list)
    for ds in StaticDataSourceConfiguration.all():
        ds_engine_id = ds['engine_id']
        by_engine_id[ds_engine_id].append(ds)

    for ds in DataSourceConfiguration.all():
        ds_engine_id = ds['engine_id']
        by_engine_id[ds_engine_id].append(ds)

    return by_engine_id
开发者ID:dimagi,项目名称:commcare-hq,代码行数:13,代码来源:0009_rename_ucr_tables.py

示例4: handle

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import all [as 别名]
    def handle(self, **options):
        data_sources = list(DataSourceConfiguration.all())
        data_sources.extend(list(StaticDataSourceConfiguration.all()))

        tables_by_engine_id = self._get_tables_by_engine_id(data_sources, options.get('engine_id'))

        tables_to_remove_by_engine = defaultdict(list)
        for engine_id, expected_tables in tables_by_engine_id.items():
            engine = connection_manager.get_engine(engine_id)
            with engine.begin() as connection:
                results = connection.execute("""
                SELECT table_name
                  FROM information_schema.tables
                WHERE table_schema='public'
                  AND table_type='BASE TABLE'
                  AND (
                    table_name LIKE '{}%%'
                    OR
                    table_name LIKE '{}%%'
                );
                """.format(UCR_TABLE_PREFIX, LEGACY_UCR_TABLE_PREFIX)).fetchall()
                tables_in_db = {r[0] for r in results}

            tables_to_remove_by_engine[engine_id] = tables_in_db - expected_tables

        for engine_id, tablenames in tables_to_remove_by_engine.items():
            print("\nTables no longer referenced in database: {}:\n".format(engine_id))
            engine = connection_manager.get_engine(engine_id)
            if not tablenames:
                print("\t No tables to prune")
                continue

            for tablename in tablenames:
                if options['show_counts']:
                    with engine.begin() as connection:
                        try:
                            result = connection.execute(
                                'SELECT COUNT(*), MAX(inserted_at) FROM "{tablename}"'.format(tablename=tablename)
                            )
                        except Exception:
                            print("\t{}: no inserted_at column, probably not UCR".format(tablename))
                        else:
                            print("\t{}: {}".foramt(tablename, result.fetchone()))
                else:
                    print("\t{}".format(tablename))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:47,代码来源:prune_old_datasources.py

示例5: test_data_sources_actually_exist

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import all [as 别名]
    def test_data_sources_actually_exist(self):

        data_sources_on_domain = defaultdict(set)
        for data_source in StaticDataSourceConfiguration.all():
            data_sources_on_domain[data_source.domain].add(data_source.get_id)

        def has_no_data_source(report_config):
            available_data_sources = data_sources_on_domain[report_config.domain]
            return report_config.config_id not in available_data_sources

        all_configs = StaticReportConfiguration.all()
        configs_missing_data_source = list(filter(has_no_data_source, all_configs))

        msg = ("There are {} report configs which reference data sources that "
               "don't exist (or which don't exist on that domain):\n{}".format(
                   len(configs_missing_data_source),
                   "\n".join(config.get_id for config in configs_missing_data_source)))
        self.assertEqual(0, len(configs_missing_data_source), msg)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:20,代码来源:test_static_reports.py

示例6: test_production_config

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import all [as 别名]
 def test_production_config(self):
     for data_source in StaticDataSourceConfiguration.all():
         data_source.validate()
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:5,代码来源:test_static_data_sources.py

示例7: get_all_configs

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import all [as 别名]
 def get_all_configs(self):
     return StaticDataSourceConfiguration.all()
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:4,代码来源:pillow.py

示例8: test_deactivate_noop

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import all [as 别名]
 def test_deactivate_noop(self):
     with override_settings(STATIC_DATA_SOURCES=[self.get_path('sample_static_data_source', 'json')]):
         example = list(StaticDataSourceConfiguration.all())[0]
         # since this is a SimpleTest, this should fail if the call actually hits the DB
         example.deactivate()
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:7,代码来源:test_static_data_sources.py

示例9: test_is_static_positive

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import all [as 别名]
 def test_is_static_positive(self):
     with override_settings(STATIC_DATA_SOURCES=[self.get_path('sample_static_data_source', 'json')]):
         example = list(StaticDataSourceConfiguration.all())[0]
         self.assertTrue(example.is_static)
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:6,代码来源:test_static_data_sources.py

示例10: get_data_sources

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import all [as 别名]
 def get_data_sources(self):
     return StaticDataSourceConfiguration.all()
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:4,代码来源:data_source_providers.py


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