Exemplo n.º 1
0
def _get_or_create_datasource_link(domain_link, datasource):
    domain_datsources = get_datasources_for_domain(domain_link.linked_domain)
    existing_linked_datasources = [d for d in domain_datsources if d.meta.master_id == datasource.get_id]
    if existing_linked_datasources:
        return existing_linked_datasources[0]

    datasource_json = datasource.to_json()
    datasource_json["domain"] = domain_link.linked_domain
    datasource_json["_id"] = None
    datasource_json["_rev"] = None

    # app_id is needed to edit a report in report builder, but linked
    # reports can't be edited, so we can ignore this
    datasource_json["meta"]["build"]["app_id"] = None

    datasource_json["meta"]["master_id"] = datasource.get_id

    _replace_master_app_ids(domain_link.linked_domain, datasource_json)

    new_datasource = DataSourceConfiguration.wrap(datasource_json)
    new_datasource.save()

    rebuild_indicators.delay(new_datasource.get_id, source=f"Datasource link: {new_datasource.get_id}")

    return new_datasource
Exemplo n.º 2
0
def _get_or_create_datasource_link(domain_link, datasource, app_id):
    domain_datsources = get_datasources_for_domain(domain_link.linked_domain)
    existing_linked_datasources = [d for d in domain_datsources if d.meta.master_id == datasource.get_id]
    if existing_linked_datasources:
        return existing_linked_datasources[0]

    datasource_json = datasource.to_json()
    datasource_json["domain"] = domain_link.linked_domain
    datasource_json["_id"] = None
    datasource_json["_rev"] = None

    # app_id is needed to edit reports which is not possible with a linked project due to master_id
    # this is to ensure if the link is removed, the downstream report will be editable
    datasource_json["meta"]["build"]["app_id"] = app_id

    datasource_json["meta"]["master_id"] = datasource.get_id

    _replace_master_app_ids(domain_link.linked_domain, datasource_json)

    new_datasource = DataSourceConfiguration.wrap(datasource_json)
    new_datasource.save()

    rebuild_indicators.delay(
        new_datasource.get_id,
        source=f"Datasource link: {new_datasource.get_id}",
        domain=new_datasource.domain
    )

    return new_datasource
Exemplo n.º 3
0
 def rebuild_table(self, adapter):
     config = adapter.config
     if not config.is_static:
         latest_rev = config.get_db().get_rev(config._id)
         if config._rev != latest_rev:
             raise StaleRebuildError('Tried to rebuild a stale table ({})! Ignoring...'.format(config))
     adapter.rebuild_table()
     if config.is_static:
         rebuild_indicators.delay(adapter.config.get_id)
Exemplo n.º 4
0
 def rebuild_table(self, adapter):
     config = adapter.config
     if not config.is_static:
         latest_rev = config.get_db().get_rev(config._id)
         if config._rev != latest_rev:
             raise StaleRebuildError('Tried to rebuild a stale table ({})! Ignoring...'.format(config))
     adapter.rebuild_table()
     if config.is_static:
         rebuild_indicators.delay(adapter.config.get_id)
Exemplo n.º 5
0
 def rebuild_table(self, sql_adapter):
     config = sql_adapter.config
     if not is_static(config._id):
         latest_rev = config.get_db().get_rev(config._id)
         if config._rev != latest_rev:
             raise StaleRebuildError('Tried to rebuild a stale table ({})! Ignoring...'.format(config))
     sql_adapter.rebuild_table()
     if self.auto_repopulate_tables:
         rebuild_indicators.delay(sql_adapter.config.get_id)
Exemplo n.º 6
0
def rebuild_data_source(request, domain, config_id):
    config = get_document_or_404(DataSourceConfiguration, domain, config_id)
    messages.success(
        request,
        _('Table "{}" is now being rebuilt. Data should start showing up soon').format(
            config.display_name
        )
    )
    rebuild_indicators.delay(config_id)
    return HttpResponseRedirect(reverse('edit_configurable_data_source', args=[domain, config._id]))
Exemplo n.º 7
0
def rebuild_data_source(request, domain, config_id):
    config, is_static = get_datasource_config_or_404(config_id, domain)
    messages.success(
        request,
        _('Table "{}" is now being rebuilt. Data should start showing up soon'
          ).format(config.display_name))

    rebuild_indicators.delay(config_id)
    return HttpResponseRedirect(
        reverse('edit_configurable_data_source', args=[domain, config._id]))
Exemplo n.º 8
0
    def rebuild_table(self, adapter, diffs=None):
        config = adapter.config
        if not config.is_static:
            latest_rev = config.get_db().get_rev(config._id)
            if config._rev != latest_rev:
                raise StaleRebuildError('Tried to rebuild a stale table ({})! Ignoring...'.format(config))

        diff_dicts = [diff.to_dict() for diff in diffs]
        if config.disable_destructive_rebuild and adapter.table_exists:
            adapter.log_table_rebuild_skipped(source='pillowtop', diffs=diff_dicts)
            return

        rebuild_indicators.delay(adapter.config.get_id, source='pillowtop', engine_id=adapter.engine_id, diffs=diff_dicts)
Exemplo n.º 9
0
def rebuild_data_source(request, domain, config_id):
    config, is_static = get_datasource_config_or_404(config_id, domain)
    if config.is_deactivated:
        config.is_deactivated = False
        config.save()

    messages.success(
        request,
        _('Table "{}" is now being rebuilt. Data should start showing up soon'
          ).format(config.display_name))

    rebuild_indicators.delay(config_id, request.user.username)
    return HttpResponseRedirect(
        reverse(EditDataSourceView.urlname, args=[domain, config._id]))
Exemplo n.º 10
0
def rebuild_data_source(request, domain, config_id):
    config, is_static = get_datasource_config_or_404(config_id, domain)
    if config.is_deactivated:
        config.is_deactivated = False
        config.save()

    messages.success(
        request,
        _('Table "{}" is now being rebuilt. Data should start showing up soon').format(
            config.display_name
        )
    )

    rebuild_indicators.delay(config_id)
    return HttpResponseRedirect(reverse('edit_configurable_data_source', args=[domain, config._id]))
Exemplo n.º 11
0
def _update_linked_datasource(master_datasource, linked_datasource):
    master_datasource_json = master_datasource.to_json()
    linked_datasource_json = linked_datasource.to_json()

    master_datasource_json["domain"] = linked_datasource_json["domain"]
    master_datasource_json["_id"] = linked_datasource_json["_id"]
    master_datasource_json["_rev"] = linked_datasource_json["_rev"]
    master_datasource_json["meta"]["master_id"] = linked_datasource_json["meta"]["master_id"]

    _replace_master_app_ids(linked_datasource_json["domain"], master_datasource_json)

    linked_datasource_json.update(master_datasource_json)
    DataSourceConfiguration.wrap(linked_datasource_json).save()

    rebuild_indicators.delay(linked_datasource.get_id, source=f"Datasource link: {linked_datasource.get_id}")
Exemplo n.º 12
0
 def response_report_builder(project, new_plan_version):
     from corehq.apps.userreports.models import ReportConfiguration
     from corehq.apps.userreports.tasks import rebuild_indicators
     reports = ReportConfiguration.by_domain(project.name)
     builder_reports = [report for report in reports if report.report_meta.created_by_builder]
     for report in builder_reports:
         try:
             report.visible = True
             report.save()
             if report.config.is_deactivated:
                 report.config.is_deactivated = False
                 report.config.save()
                 rebuild_indicators.delay(report.config._id)
         except DataSourceConfigurationNotFoundError:
             pass
     return True
Exemplo n.º 13
0
 def rebuild_table(self, sql_adapter):
     super(StaticDataSourcePillow, self).rebuild_table(sql_adapter)
     rebuild_indicators.delay(sql_adapter.config.get_id)
Exemplo n.º 14
0
 def rebuild_table(self, table):
     super(CustomDataSourcePillow, self).rebuild_table(table)
     rebuild_indicators.delay(table.config.get_id)
Exemplo n.º 15
0
 def rebuild_table(self, table):
     super(CustomDataSourcePillow, self).rebuild_table(table)
     rebuild_indicators.delay(table.config.get_id)