<commit_before>from django.forms import CharField, ChoiceField, ModelChoiceField
from registration.backends.default.views import\
    RegistrationView as OldRegistrationView,\
    ActivationView as OldActivationView
from registration.forms import RegistrationForm
from judge.models import Profile, Language, TIMEZONE


class CustomRegistrationForm(RegistrationForm):
    display_name = CharField(max_length=50, required=False, label='Display name (optional)')
    timezone = ChoiceField(max_length=50, choices=TIMEZONE)
    language = ModelChoiceField(queryset=Language.objects.all(), label='Default language')


class RegistrationView(OldRegistrationView):
    title = 'Registration'
    form_class = CustomRegistrationForm
    template_name = 'registration/registration_form.jade'

    def get_context_data(self, **kwargs):
        if 'title' not in kwargs:
            kwargs['title'] = self.title
        return super(RegistrationView, self).get_context_data(**kwargs)

    def register(self, request, **cleaned_data):
        user = super(RegistrationView, self).register(request, **cleaned_data)
        profile, _ = Profile.objects.get_or_create(user=user, defaults={
            'language': Language.objects.get_or_create(key='PY2', name='Python 2')[0]
        })
        profile.name = cleaned_data['display_name']
        profile.timezone = cleaned_data['timezone']
        profile.language = cleaned_data['language']
        profile.save()
        return user<commit_msg>Forms are apparently not very similar to models<commit_after>from django.forms import CharField, ChoiceField, ModelChoiceField
from registration.backends.default.views import\
    RegistrationView as OldRegistrationView,\
    ActivationView as OldActivationView
from registration.forms import RegistrationForm
from judge.models import Profile, Language, TIMEZONE


class CustomRegistrationForm(RegistrationForm):
    display_name = CharField(max_length=50, required=False, label='Display name (optional)')
    timezone = ChoiceField(choices=TIMEZONE)
    language = ModelChoiceField(queryset=Language.objects.all(), label='Default language')


class RegistrationView(OldRegistrationView):
    title = 'Registration'
    form_class = CustomRegistrationForm
    template_name = 'registration/registration_form.jade'

    def get_context_data(self, **kwargs):
        if 'title' not in kwargs:
            kwargs['title'] = self.title
        return super(RegistrationView, self).get_context_data(**kwargs)

    def register(self, request, **cleaned_data):
        user = super(RegistrationView, self).register(request, **cleaned_data)
        profile, _ = Profile.objects.get_or_create(user=user, defaults={
            'language': Language.objects.get_or_create(key='PY2', name='Python 2')[0]
        })
        profile.name = cleaned_data['display_name']
        profile.timezone = cleaned_data['timezone']
        profile.language = cleaned_data['language']
        profile.save()
        return user
{'fraction_non_alphanumeric': 0.0992289641300704, 'fraction_numerical': 0.004022795843110962, 'mean_word_length': 4.435336976320583, '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': '1515263', 'n_tokens_mistral': 802, 'n_tokens_neox': 776, 'n_words': 175}