def group_name(owner_id): results = get_group_id_name_map_by_user(owner_id, limit=1) if results: return results[0].name else: try: return Group.get(owner_id).name except ResourceNotFound: return "No Group"
def transform_user_for_elasticsearch(doc_dict): doc = copy.deepcopy(doc_dict) if doc['doc_type'] == 'CommCareUser' and '@' in doc['username']: doc['base_username'] = doc['username'].split("@")[0] else: doc['base_username'] = doc['username'] results = get_group_id_name_map_by_user(doc['_id']) doc['__group_ids'] = [res.id for res in results] doc['__group_names'] = [res.name for res in results] doc['user_data_es'] = [] if 'user_data' in doc: for key, value in doc['user_data'].items(): doc['user_data_es'].append({ 'key': key, 'value': value, }) return doc
def transform_user_for_elasticsearch(doc_dict): doc = copy.deepcopy(doc_dict) if doc['doc_type'] == 'CommCareUser' and '@' in doc['username']: doc['base_username'] = doc['username'].split("@")[0] else: doc['base_username'] = doc['username'] results = get_group_id_name_map_by_user(doc['_id']) doc['__group_ids'] = [res.id for res in results] doc['__group_names'] = [res.name for res in results] doc['user_data_es'] = [] if 'user_data' in doc: from corehq.apps.users.models import CouchUser user = CouchUser.wrap_correctly(doc) for key, value in user.metadata.items(): doc['user_data_es'].append({ 'key': key, 'value': value, }) return doc