'Populates a User profile object with fields from the LDAP directory.'

def _populate_and_save_user_profile(self):

    try:
        profile = self._user.get_profile()
        save_profile = False
        logger.debug('Populating    Django    user    profile    for    %s', get_user_username(self._user))
        save_profile = (self._populate_profile_from_attributes(profile) or save_profile)
        save_profile = (self._populate_profile_from_group_memberships(profile) or save_profile)
        signal_responses = populate_user_profile.send(self.backend.__class__, profile=profile, ldap_user=self)
        if (len(signal_responses) > 0):
            save_profile = True
        if save_profile:
            profile.save()
    except (SiteProfileNotAvailable, ObjectDoesNotExist):
        logger.debug('Django    user    %s    does    not    have    a    profile    to    populate', get_user_username(self._user))
