(domain, modified_forms, modified_cases, is_deletion)
return [form.form_id for form in all_forms if _is_safe_to_modify(form)]
Used on user.retire() and user.unretire()

    Returns a list of IDs of forms which only modify the cases passed in and
    which aren't already listed in `modified_forms`.
Used on user.retire() and user.unretire()
Used on user . retire () and user . unretire ()
def _get_forms_to_modify(domain, modified_forms, modified_cases, is_deletion):
    """Used on user.retire() and user.unretire()

    Returns a list of IDs of forms which only modify the cases passed in and
    which aren't already listed in `modified_forms`.
    """
    form_ids_to_modify = set()
    for case_id in modified_cases:
        try:
            xform_ids = CaseAccessors(domain).get_case(case_id).xform_ids
        except CaseNotFound:
            xform_ids = []
        form_ids_to_modify |= set(xform_ids) - modified_forms

    def _is_safe_to_modify(form):
        if form.domain != domain:
            return False

        case_ids = get_case_ids_from_form(form)
        # all cases touched by the form and not already modified
        for case in CaseAccessors(domain).iter_cases(case_ids - modified_cases):
            if case.is_deleted != is_deletion:
                # we can't delete/undelete this form - this would change the state of `case`
                return False

        # all cases touched by this form are deleted
        return True

    all_forms = FormAccessors(domain).iter_forms(form_ids_to_modify)
    return [form.form_id for form in all_forms if _is_safe_to_modify(form)]
def _get_forms_to_modify ( domain , modified_forms , modified_cases , is_deletion ) : form_ids_to_modify = set ( ) for case_id in modified_cases : try : xform_ids = CaseAccessors ( domain ) . get_case ( case_id ) . xform_ids except CaseNotFound : xform_ids = [ ] form_ids_to_modify |= set ( xform_ids ) - modified_forms def _is_safe_to_modify ( form ) : if form . domain != domain : return False case_ids = get_case_ids_from_form ( form ) # all cases touched by the form and not already modified for case in CaseAccessors ( domain ) . iter_cases ( case_ids - modified_cases ) : if case . is_deleted != is_deletion : # we can't delete/undelete this form - this would change the state of `case` return False # all cases touched by this form are deleted return True all_forms = FormAccessors ( domain ) . iter_forms ( form_ids_to_modify ) return [ form . form_id for form in all_forms if _is_safe_to_modify ( form ) ]