<commit_before>from django.contrib.auth.backends import ModelBackend
from django.contrib.auth import get_user_model
from django.db import IntegrityError

from wafer.users.models import UserProfile


class GitHubBackend(ModelBackend):

    def authenticate(self, github_login, name, email, blog):
        if not github_login:
            return
        try:
            return UserProfile.objects.get(github_username=github_login).user
        except UserProfile.DoesNotExist:
            return self._create_user(github_login, name, email, blog)

    def _create_user(self, github_login, name, email, blog, append=0):
        try:
            user = get_user_model().objects.create(
                    username=(github_login + str(append)
                              if append else github_login))
        except IntegrityError:
            return self._create_user(github_login, name, email, blog,
                                     append + 1)

        if name:
            user.first_name, _,  user.last_name = name.partition(' ')
        user.email = email
        user.save()

        profile = user.get_profile()
        profile.homepage = blog
        profile.github_username = github_login
        profile.save()

        return user<commit_msg>drop use of get_profile in registration<commit_after>from django.contrib.auth.backends import ModelBackend
from django.contrib.auth import get_user_model
from django.db import IntegrityError

from wafer.users.models import UserProfile


class GitHubBackend(ModelBackend):

    def authenticate(self, github_login, name, email, blog):
        if not github_login:
            return
        try:
            return UserProfile.objects.get(github_username=github_login).user
        except UserProfile.DoesNotExist:
            return self._create_user(github_login, name, email, blog)

    def _create_user(self, github_login, name, email, blog, append=0):
        try:
            user = get_user_model().objects.create(
                    username=(github_login + str(append)
                              if append else github_login))
        except IntegrityError:
            return self._create_user(github_login, name, email, blog,
                                     append + 1)

        if name:
            user.first_name, _,  user.last_name = name.partition(' ')
        user.email = email
        user.save()

        profile = user.userprofile
        profile.homepage = blog
        profile.github_username = github_login
        profile.save()

        return user
{'fraction_non_alphanumeric': 0.07486209613869188, 'fraction_numerical': 0.0015760441292356187, 'mean_word_length': 2.197732997481108, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2206319', 'n_tokens_mistral': 678, 'n_tokens_neox': 649, 'n_words': 164}