<commit_before>from django.conf import settings

try:
    from django_auth_ldap.backend import LDAPBackend
    class NumbasAuthBackend(LDAPBackend):
        
        """Authentication backend overriding LDAPBackend.
        
        This could be used to override certain functionality within the LDAP authentication backend.
        The example here overrides get_or_create_user() to alter the LDAP givenName attribute.
        
        To use this backend, edit settings.py and replace the LDAPBackend line in AUTHENTICATION_BACKENDS with
            numbas_auth.NumbasAuthBackend
            
        """
        
        def get_or_create_user(self, username, ldap_user):
            """Alter the LDAP givenName attribute to the familiar first name in displayName."""
            
            ldap_user.attrs['givenName'] = [ldap_user.attrs['displayName'][0].split()[0]]
            return super(NumbasAuthBackend, self).get_or_create_user(username, ldap_user)
except ImportError:
    pass
<commit_msg>reset personal project name when creating a user through LDAP auth<commit_after>from django.conf import settings

try:
    from django_auth_ldap.backend import LDAPBackend
    class NumbasAuthBackend(LDAPBackend):
        
        """Authentication backend overriding LDAPBackend.
        
        This could be used to override certain functionality within the LDAP authentication backend.
        The example here overrides get_or_create_user() to alter the LDAP givenName attribute.
        
        To use this backend, edit settings.py and replace the LDAPBackend line in AUTHENTICATION_BACKENDS with
            numbas_auth.NumbasAuthBackend
            
        """
        
        def get_or_create_user(self, username, ldap_user):
            """Alter the LDAP givenName attribute to the familiar first name in displayName."""
            
            ldap_user.attrs['givenName'] = [ldap_user.attrs['displayName'][0].split()[0]]
            user,created = super(NumbasAuthBackend, self).get_or_create_user(username, ldap_user)
            if created:
                p = user.userprofile.personal_project
                p.name = "{}'s workspace".format(ldap_user.attrs['givenName'][0])
                p.save()
            return user,created
except ImportError:
    pass

{'fraction_non_alphanumeric': 0.06681222707423581, 'fraction_numerical': 0.002183406113537118, 'mean_word_length': 2.6365079365079365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6848431', 'n_tokens_mistral': 596, 'n_tokens_neox': 604, 'n_words': 178}