(domain=None, group=None, user_ids=None,
                            user_filter=None, simplified=False, CommCareUser=None, include_inactive=False)
return users
WHEN THERE ARE A LOT OF USERS, THIS IS AN EXPENSIVE OPERATION.
        Returns a list of CommCare Users based on domain, group, and user 
        filter (demo_user, admin, registered, unknown)
WHEN THERE ARE A LOT OF USERS, THIS IS AN EXPENSIVE OPERATION.
        Returns a list of CommCare Users based on domain, group, and user 
        filter (demo_user, admin, registered, unknown)
WHEN THERE ARE A LOT OF USERS THIS IS AN EXPENSIVE OPERATION . Returns a list of CommCare Users based on domain group and user filter ( demo_user admin registered unknown )
def get_all_users_by_domain(domain=None, group=None, user_ids=None,
                            user_filter=None, simplified=False, CommCareUser=None, include_inactive=False):
    """
        WHEN THERE ARE A LOT OF USERS, THIS IS AN EXPENSIVE OPERATION.
        Returns a list of CommCare Users based on domain, group, and user 
        filter (demo_user, admin, registered, unknown)
    """
    def _create_temp_user(user_id):
        username = get_username_from_forms(domain, user_id).lower()
        temp_user = TempCommCareUser(domain, username, user_id)
        if user_filter[temp_user.filter_flag].show:
            return temp_user
        return None

    user_ids = user_ids or []
    user_ids = [_f for _f in user_ids if _f]  # remove empty strings if any
    if not CommCareUser:
        from corehq.apps.users.models import CommCareUser

    if group:
        # get all the users only in this group and don't bother filtering.
        if not isinstance(group, Group):
            group = Group.get(group)
        users = group.get_users(is_active=(not include_inactive), only_commcare=True)
    elif user_ids:
        try:
            users = []
            for id in user_ids:
                user = CommCareUser.get_by_user_id(id)
                if not user and (user_filter[HQUserType.ADMIN].show or
                      user_filter[HQUserType.DEMO_USER].show or
                      user_filter[HQUserType.UNKNOWN].show):
                    user = _create_temp_user(id)
                if user:
                    users.append(user)
        except Exception:
            users = []
        if users and users[0] is None:
            raise Http404()
    else:
        if not user_filter:
            user_filter = HQUserType.all()
        users = []
        submitted_user_ids = set(get_all_user_ids_submitted(domain))
        registered_users_by_id = dict([(user.user_id, user) for user in CommCareUser.by_domain(domain)])
        if include_inactive:
            registered_users_by_id.update(dict(
                [(u.user_id, u) for u in CommCareUser.by_domain(domain, is_active=False)]
            ))
        for user_id in submitted_user_ids:
            if user_id in registered_users_by_id and user_filter[HQUserType.ACTIVE].show:
                user = registered_users_by_id[user_id]
                users.append(user)
            elif (user_id not in registered_users_by_id and
                 (user_filter[HQUserType.ADMIN].show or
                  user_filter[HQUserType.DEMO_USER].show or
                  user_filter[HQUserType.UNKNOWN].show)):
                user = _create_temp_user(user_id)
                if user:
                    users.append(user)
        if user_filter[HQUserType.UNKNOWN].show:
            users.append(TempCommCareUser(domain, '*', None))

        if user_filter[HQUserType.ACTIVE].show:
            # now add all the registered users who never submitted anything
            users.extend(user for id, user in registered_users_by_id.items() if id not in submitted_user_ids)

    if simplified:
        return [_report_user_dict(user) for user in users]
    return users
def get_all_users_by_domain ( domain = None , group = None , user_ids = None , user_filter = None , simplified = False , CommCareUser = None , include_inactive = False ) : def _create_temp_user ( user_id ) : username = get_username_from_forms ( domain , user_id ) . lower ( ) temp_user = TempCommCareUser ( domain , username , user_id ) if user_filter [ temp_user . filter_flag ] . show : return temp_user return None user_ids = user_ids or [ ] user_ids = [ _f for _f in user_ids if _f ] # remove empty strings if any if not CommCareUser : from corehq . apps . users . models import CommCareUser if group : # get all the users only in this group and don't bother filtering. if not isinstance ( group , Group ) : group = Group . get ( group ) users = group . get_users ( is_active = ( not include_inactive ) , only_commcare = True ) elif user_ids : try : users = [ ] for id in user_ids : user = CommCareUser . get_by_user_id ( id ) if not user and ( user_filter [ HQUserType . ADMIN ] . show or user_filter [ HQUserType . DEMO_USER ] . show or user_filter [ HQUserType . UNKNOWN ] . show ) : user = _create_temp_user ( id ) if user : users . append ( user ) except Exception : users = [ ] if users and users [ 0 ] is None : raise Http404 ( ) else : if not user_filter : user_filter = HQUserType . all ( ) users = [ ] submitted_user_ids = set ( get_all_user_ids_submitted ( domain ) ) registered_users_by_id = dict ( [ ( user . user_id , user ) for user in CommCareUser . by_domain ( domain ) ] ) if include_inactive : registered_users_by_id . update ( dict ( [ ( u . user_id , u ) for u in CommCareUser . by_domain ( domain , is_active = False ) ] ) ) for user_id in submitted_user_ids : if user_id in registered_users_by_id and user_filter [ HQUserType . ACTIVE ] . show : user = registered_users_by_id [ user_id ] users . append ( user ) elif ( user_id not in registered_users_by_id and ( user_filter [ HQUserType . ADMIN ] . show or user_filter [ HQUserType . DEMO_USER ] . show or user_filter [ HQUserType . UNKNOWN ] . show ) ) : user = _create_temp_user ( user_id ) if user : users . append ( user ) if user_filter [ HQUserType . UNKNOWN ] . show : users . append ( TempCommCareUser ( domain , '*' , None ) ) if user_filter [ HQUserType . ACTIVE ] . show : # now add all the registered users who never submitted anything users . extend ( user for id , user in registered_users_by_id . items ( ) if id not in submitted_user_ids ) if simplified : return [ _report_user_dict ( user ) for user in users ] return users