(user)
Accepts a user object or a dict such as that returned from elasticsearch.
    Make sure the following fields are available:
    ['_id', 'username', 'first_name', 'last_name', 'doc_type', 'is_active']
Accepts a user object or a dict such as that returned from elasticsearch.
    Make sure the following fields are available:
    ['_id', 'username', 'first_name', 'last_name', 'doc_type', 'is_active']
Accepts a user object or a dict such as that returned from elasticsearch . Make sure the following fields are available : [ _id username first_name last_name doc_type is_active ]
def _report_user_dict(user):
    """
    Accepts a user object or a dict such as that returned from elasticsearch.
    Make sure the following fields are available:
    ['_id', 'username', 'first_name', 'last_name', 'doc_type', 'is_active']
    """
    if not isinstance(user, dict):
        user_report_attrs = [
            'user_id', 'username_in_report', 'raw_username', 'is_active', 'location_id'
        ]
        return SimplifiedUserInfo(**{attr: getattr(user, attr)
                                     for attr in user_report_attrs})
    else:
        username = user.get('username', '')
        raw_username = (username.split("@")[0]
                        if user.get('doc_type', '') == "CommCareUser"
                        else username)
        first = user.get('first_name', '')
        last = user.get('last_name', '')
        username_in_report = _get_username_fragment(raw_username, first, last)
        info = SimplifiedUserInfo(
            user_id=user.get('_id', ''),
            username_in_report=username_in_report,
            raw_username=raw_username,
            is_active=user.get('is_active', None),
            location_id=user.get('location_id', None)
        )
        if '__group_ids' in user:
            group_ids = user['__group_ids']
            info.__group_ids = group_ids if isinstance(group_ids, list) else [group_ids]
        return info
def _report_user_dict ( user ) : if not isinstance ( user , dict ) : user_report_attrs = [ 'user_id' , 'username_in_report' , 'raw_username' , 'is_active' , 'location_id' ] return SimplifiedUserInfo ( * * { attr : getattr ( user , attr ) for attr in user_report_attrs } ) else : username = user . get ( 'username' , '' ) raw_username = ( username . split ( "@" ) [ 0 ] if user . get ( 'doc_type' , '' ) == "CommCareUser" else username ) first = user . get ( 'first_name' , '' ) last = user . get ( 'last_name' , '' ) username_in_report = _get_username_fragment ( raw_username , first , last ) info = SimplifiedUserInfo ( user_id = user . get ( '_id' , '' ) , username_in_report = username_in_report , raw_username = raw_username , is_active = user . get ( 'is_active' , None ) , location_id = user . get ( 'location_id' , None ) ) if '__group_ids' in user : group_ids = user [ '__group_ids' ] info . __group_ids = group_ids if isinstance ( group_ids , list ) else [ group_ids ] return info