<s> from corehq . apps . casegroups . models import CommCareCaseGroup <EOL> from corehq . apps . domain . dbaccessors import ( <EOL> get_doc_ids_in_domain_by_class , <EOL> get_docs_in_domain_by_class , <EOL> ) <EOL> def get_case_groups_in_domain ( domain , limit = None , skip = None ) : <EOL> def _get_case_groups_generator ( domain_name ) : <EOL> for case_group in get_docs_in_domain_by_class ( domain_name , CommCareCaseGroup ) : <EOL> yield case_group <EOL> case_groups_generator = _get_case_groups_generator ( domain ) <EOL> if skip is not None : <EOL> try : <EOL> for _ in range ( skip ) : <EOL> next ( case_groups_generator ) <EOL> except StopIteration : <EOL> pass <EOL> if limit is not None : <EOL> return list ( next ( case_groups_generator ) for _ in range ( limit ) ) <EOL> return list ( case_groups_generator ) <EOL> def get_case_group_meta_in_domain ( domain ) : <EOL> """<STR_LIT>""" <EOL> return sorted ( <EOL> map ( <EOL> lambda case_group : ( case_group . _id , case_group . name ) , <EOL> get_docs_in_domain_by_class ( domain , CommCareCaseGroup ) <EOL> ) , <EOL> key = lambda id_name_tuple : id_name_tuple [ <NUM_LIT:1> ] <EOL> ) <EOL> def get_number_of_case_groups_in_domain ( domain ) : <EOL> return len ( get_doc_ids_in_domain_by_class ( domain , CommCareCaseGroup ) ) </s>
