コード例 #1
0
ファイル: tasks.py プロジェクト: solleks/commcare-hq
def update_facility_cases_from_dhis2_data_elements(
    period: Optional[str] = None,
    print_notifications: bool = False,
):
    """
    Update facility_supervision cases with indicators collected in DHIS2
    over the last quarter.

    :param period: The period of data to import. e.g. "2020Q1". Defaults
        to last quarter.
    :param print_notifications: If True, notifications are printed,
        otherwise they are emailed.

    """
    if not domain_exists(DOMAIN):
        return
    dhis2_server = get_dhis2_server(print_notifications)
    try:
        clays = get_clays()
        with ThreadPoolExecutor(max_workers=MAX_THREAD_WORKERS) as executor:
            futures = (executor.submit(set_case_updates, dhis2_server, clay,
                                       period) for clay in clays)
            for futures_chunk in chunked(as_completed(futures), 100):
                case_blocks_chunk = [f.result() for f in futures_chunk]
                save_cases(case_blocks_chunk)
    except Exception as err:
        handle_error(err, dhis2_server, print_notifications)
    else:
        handle_success(dhis2_server, print_notifications)
コード例 #2
0
    def test_deleted_domain_exists(self):
        x = Domain(name='x')
        x.save()
        y = Domain(name='y')
        y.save()
        y.delete(leave_tombstone=True)
        self.addCleanup(x.delete)
        self.addCleanup(y.delete)
        self.assertTrue(domain_exists('x'))
        self.assertFalse(deleted_domain_exists('x'))
        self.assertTrue(domain_or_deleted_domain_exists('x'))

        self.assertFalse(domain_exists('y'))
        self.assertTrue(deleted_domain_exists('y'))
        self.assertTrue(domain_or_deleted_domain_exists('y'))

        self.assertTrue(len(list(iter_all_domains_and_deleted_domains_with_name('x'))), 1)
        self.assertTrue(len(list(iter_all_domains_and_deleted_domains_with_name('y'))), 1)
コード例 #3
0
ファイル: views.py プロジェクト: soitun/commcare-hq
def link_domains(couch_user, upstream_domain, downstream_domain):
    if not domain_exists(downstream_domain):
        error = gettext("The project space {} does not exist. Verify that the name is correct, and that the "
                        "domain has not been deleted.").format(downstream_domain)
        raise DomainDoesNotExist(error)

    if get_active_domain_link(upstream_domain, downstream_domain):
        error = gettext(
            "The project space {} is already a downstream project space of {}."
        ).format(downstream_domain, upstream_domain)
        raise DomainLinkAlreadyExists(error)

    if not user_has_admin_access_in_all_domains(couch_user, [upstream_domain, downstream_domain]):
        error = gettext("You must be an admin in both project spaces to create a link.")
        raise DomainLinkNotAllowed(error)

    return DomainLink.link_domains(downstream_domain, upstream_domain)
コード例 #4
0
def should_create_invoice(subscription, domain, invoice_start, invoice_end):
    if not domain_exists(domain) and deleted_domain_exists(domain):
        # domain has been deleted, ignore
        return False
    if subscription.is_trial:
        log_accounting_info(
            "Skipping invoicing for Subscription %s because it's a trial." %
            subscription.pk)
        return False
    if subscription.skip_invoicing_if_no_feature_charges and not \
            subscription.plan_version.feature_charges_exist_for_domain(domain):
        log_accounting_info(
            "Skipping invoicing for Subscription %s because there are no feature charges."
            % subscription.pk)
        return False
    if subscription.date_start > invoice_end:
        # No invoice gets created if the subscription didn't start in the previous month.
        return False
    if subscription.date_end and subscription.date_end <= invoice_start:
        # No invoice gets created if the subscription ended before the invoicing period.
        return False
    return True