本文整理汇总了Python中corehq.apps.userreports.models.StaticDataSourceConfiguration.by_domain方法的典型用法代码示例。如果您正苦于以下问题:Python StaticDataSourceConfiguration.by_domain方法的具体用法?Python StaticDataSourceConfiguration.by_domain怎么用?Python StaticDataSourceConfiguration.by_domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.userreports.models.StaticDataSourceConfiguration
的用法示例。
在下文中一共展示了StaticDataSourceConfiguration.by_domain方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpModule
# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_domain [as 别名]
def setUpModule():
if isinstance(Domain.get_db(), Mock):
# needed to skip setUp for javascript tests thread on Travis
return
_call_center_domain_mock = mock.patch(
'corehq.apps.callcenter.data_source.call_center_data_source_configuration_provider'
)
_call_center_domain_mock.start()
domain = create_domain('champ-cameroon')
with override_settings(SERVER_ENVIRONMENT='production'):
configs = StaticDataSourceConfiguration.by_domain(domain.name)
adapters = [get_indicator_adapter(config) for config in configs]
for adapter in adapters:
adapter.build_table()
engine = connection_manager.get_engine(UCR_ENGINE_ID)
metadata = sqlalchemy.MetaData(bind=engine)
metadata.reflect(bind=engine, extend_existing=True)
path = os.path.join(os.path.dirname(__file__), 'fixtures')
for file_name in os.listdir(path):
with open(os.path.join(path, file_name), encoding='utf-8') as f:
table_name = get_table_name(domain.name, file_name[:-4])
table = metadata.tables[table_name]
postgres_copy.copy_from(
f, table, engine, format='csv' if six.PY3 else b'csv',
null='' if six.PY3 else b'', header=True
)
_call_center_domain_mock.stop()
示例2: get_datasources_for_domain
# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_domain [as 别名]
def get_datasources_for_domain(domain, referenced_doc_type=None, include_static=False, include_aggregate=False):
from corehq.apps.userreports.models import DataSourceConfiguration, StaticDataSourceConfiguration
key = [domain]
if referenced_doc_type:
key.append(referenced_doc_type)
datasources = sorted(
DataSourceConfiguration.view(
'userreports/data_sources_by_build_info',
startkey=key,
endkey=key + [{}],
reduce=False,
include_docs=True
),
key=lambda config: config.display_name or '')
if include_static:
static_ds = StaticDataSourceConfiguration.by_domain(domain)
if referenced_doc_type:
static_ds = [ds for ds in static_ds if ds.referenced_doc_type == referenced_doc_type]
datasources.extend(sorted(static_ds, key=lambda config: config.display_name))
if include_aggregate:
from corehq.apps.aggregate_ucrs.models import AggregateTableDefinition
datasources.extend(AggregateTableDefinition.objects.filter(domain=domain).all())
return datasources
示例3: _shared_context
# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_domain [as 别名]
def _shared_context(domain):
static_reports = list(StaticReportConfiguration.by_domain(domain))
static_data_sources = list(StaticDataSourceConfiguration.by_domain(domain))
return {
'domain': domain,
'reports': ReportConfiguration.by_domain(domain) + static_reports,
'data_sources': DataSourceConfiguration.by_domain(domain) + static_data_sources,
}
示例4: handle
# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_domain [as 别名]
def handle(self, domain, **options):
tables = StaticDataSourceConfiguration.by_domain(domain)
tables.extend(DataSourceConfiguration.by_domain(domain))
print("Rebuilding {} tables".format(len(tables)))
for table in tables:
tasks.rebuild_indicators(table._id)
示例5: main_context
# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_domain [as 别名]
def main_context(self):
static_reports = list(StaticReportConfiguration.by_domain(self.domain))
static_data_sources = list(StaticDataSourceConfiguration.by_domain(self.domain))
context = super(BaseUserConfigReportsView, self).main_context
context.update({
'reports': ReportConfiguration.by_domain(self.domain) + static_reports,
'data_sources': DataSourceConfiguration.by_domain(self.domain) + static_data_sources,
})
return context
示例6: __init__
# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_domain [as 别名]
def __init__(self, domain, *args, **kwargs):
self.domain = domain
standard_sources = DataSourceConfiguration.by_domain(self.domain)
custom_sources = list(StaticDataSourceConfiguration.by_domain(domain))
available_data_sources = standard_sources + custom_sources
super(ReportDataSourceField, self).__init__(
choices=[(src._id, src.display_name) for src in available_data_sources],
*args, **kwargs
)
示例7: __init__
# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_domain [as 别名]
def __init__(self, domain, *args, **kwargs):
self.domain = domain
standard_sources = DataSourceConfiguration.by_domain(self.domain)
custom_sources = list(StaticDataSourceConfiguration.by_domain(domain))
available_data_sources = standard_sources + custom_sources
if toggles.AGGREGATE_UCRS.enabled(domain):
from corehq.apps.aggregate_ucrs.models import AggregateTableDefinition
available_data_sources += AggregateTableDefinition.objects.filter(domain=self.domain)
super(ReportDataSourceField, self).__init__(
choices=[(src.data_source_id, src.display_name) for src in available_data_sources],
*args, **kwargs
)
示例8: copy_ucr_datasources
# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_domain [as 别名]
def copy_ucr_datasources(self):
datasource_map = {}
datasources = get_datasources_for_domain(self.existing_domain)
for datasource in datasources:
datasource.meta.build.finished = False
datasource.meta.build.initiated = None
old_id, new_id = self.save_couch_copy(datasource, self.new_domain)
datasource_map[old_id] = new_id
for static_datasource in StaticDataSourceConfiguration.by_domain(self.existing_domain):
table_id = static_datasource.get_id.replace(
StaticDataSourceConfiguration._datasource_id_prefix + self.existing_domain + "-", ""
)
new_id = StaticDataSourceConfiguration.get_doc_id(self.new_domain, table_id)
# check that new datasource is in new domain's list of static datasources
StaticDataSourceConfiguration.by_id(new_id)
datasource_map[static_datasource.get_id] = new_id
return datasource_map
示例9: setUpModule
# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_domain [as 别名]
#.........这里部分代码省略.........
product_id='product1'
)
SQLProduct.objects.create(
domain='test-pna',
name='CU',
code='product2',
product_id='product2'
)
SQLProduct.objects.create(
domain='test-pna',
name='Depo-Provera',
code='product3',
product_id='product3'
)
SQLProduct.objects.create(
domain='test-pna',
name='DIU',
code='product4',
product_id='product4'
)
SQLProduct.objects.create(
domain='test-pna',
name='Jadelle',
code='product5',
product_id='product5'
)
SQLProduct.objects.create(
domain='test-pna',
name='Microgynon/Lof.',
code='product6',
product_id='product6'
)
SQLProduct.objects.create(
domain='test-pna',
name='Microlut/Ovrette',
code='product7',
product_id='product7'
)
SQLProduct.objects.create(
domain='test-pna',
name='Preservatif Feminin',
code='product8',
product_id='product8'
)
SQLProduct.objects.create(
domain='test-pna',
name='Preservatif Masculin',
code='product9',
product_id='product9'
)
SQLProduct.objects.create(
domain='test-pna',
name='Sayana Press',
code='product10',
product_id='product10'
)
SQLProduct.objects.create(
domain='test-pna',
name='IMPLANON',
code='product11',
product_id='product11'
)
SQLProduct.objects.create(
domain='test-pna',
name='Product 7',
code='p7',
product_id='p7'
)
with override_settings(SERVER_ENVIRONMENT='production'):
configs = StaticDataSourceConfiguration.by_domain(domain.name)
adapters = [get_indicator_adapter(config) for config in configs]
for adapter in adapters:
adapter.build_table()
engine = connection_manager.get_engine(UCR_ENGINE_ID)
metadata = sqlalchemy.MetaData(bind=engine)
metadata.reflect(bind=engine, extend_existing=True)
path = os.path.join(os.path.dirname(__file__), 'fixtures')
for file_name in os.listdir(path):
with open(os.path.join(path, file_name), encoding='utf-8') as f:
table_name = get_table_name(domain.name, file_name[:-4])
table = metadata.tables[table_name]
postgres_copy.copy_from(
f, table, engine, format='csv' if six.PY3 else b'csv', null='' if six.PY3 else b'', header=True
)
_call_center_domain_mock.stop()