<s> from operator import attrgetter <EOL> from django . utils . translation import ugettext_noop <EOL> from corehq . apps . groups . models import Group <EOL> from dimagi . utils . couch . cache import cache_core <EOL> ASHA_ROLE = ugettext_noop ( '<STR_LIT>' ) <EOL> AWW_ROLE = ugettext_noop ( '<STR_LIT>' ) <EOL> ANM_ROLE = ugettext_noop ( '<STR_LIT>' ) <EOL> LS_ROLE = ugettext_noop ( '<STR_LIT>' ) <EOL> FLW_ROLES = ( ASHA_ROLE , AWW_ROLE ) <EOL> SUPERVISOR_ROLES = ( ANM_ROLE , LS_ROLE ) <EOL> def get_role ( user ) : <EOL> return ( user . user_data . get ( '<STR_LIT>' ) or '<STR_LIT>' ) . upper ( ) <EOL> def get_team_members ( group , roles = FLW_ROLES ) : <EOL> """<STR_LIT>""" <EOL> users = group . get_users ( only_commcare = True ) <EOL> return sorted ( [ u for u in users if get_role ( u ) in roles ] , <EOL> key = lambda u : u . user_data [ '<STR_LIT>' ] . upper ( ) ) <EOL> def groups_for_user ( user , domain ) : <EOL> if user . is_commcare_user ( ) : <EOL> return Group . by_user ( user ) <EOL> else : <EOL> return Group . by_domain ( domain ) <EOL> def get_all_owner_ids ( user_ids ) : <EOL> all_group_ids = [ <EOL> row [ '<STR_LIT:id>' ] <EOL> for row in Group . get_db ( ) . view ( <EOL> '<STR_LIT>' , <EOL> keys = user_ids , <EOL> include_docs = False <EOL> ) <EOL> ] <EOL> return set ( user_ids ) . union ( set ( all_group_ids ) ) <EOL> def get_all_owner_ids_from_group ( group ) : <EOL> return get_all_owner_ids ( [ user . get_id for user in get_team_members ( group ) ] ) </s>
