<commit_before>from django import forms
from myhpom import validators
from myhpom.models import UserDetails, State
from myhpom.models.user import User
from .merged import MergedModelForm


class EditUserForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ['first_name', 'last_name', 'email']

    first_name = forms.CharField(
        label='First Name',
        max_length=30,
        validators=[validators.name_validator],
        error_messages={'required': 'Please enter your first name.'},
    )
    last_name = forms.CharField(
        label='Last Name',
        max_length=30,
        validators=[validators.name_validator],
        error_messages={'required': 'Please enter your last name.'},
    )
    email = forms.EmailField(label='Email Address', validators=[validators.email_validator])


class EditUserDetailsForm(forms.ModelForm):
    class Meta:
        model = UserDetails
        fields = ['middle_name', 'zip_code', 'birthdate', 'gender', 'is_organ_donor']

    state = forms.ChoiceField(
        label='State of Residence',
        choices=((state.name, state.title) for state in State.objects.all()),
        required=True,
        error_messages={'required': 'Please select your state.'},
    )

    def save(self, commit=True):
        instance = super(forms.ModelForm, self).save(commit=False)
        state = State.objects.filter(name=self.cleaned_data['state']).first()
        if state is None:
            raise ValueError("State not found: %s" % self.cleaned_data['state'])
        instance.state = state
        if commit == True:
            instance.save()
        return instance


class EditProfileForm(MergedModelForm):
    class Meta:
        forms = [EditUserForm, EditUserDetailsForm]<commit_msg>[mh-12] docstrings for the new forms.<commit_after>from django import forms
from myhpom import validators
from myhpom.models import UserDetails, State
from myhpom.models.user import User
from .merged import MergedModelForm


class EditUserForm(forms.ModelForm):
    """subform for EditProfileForm (below) to handle the User portion."""
    class Meta:
        model = User
        fields = ['first_name', 'last_name', 'email']

    first_name = forms.CharField(
        label='First Name',
        max_length=30,
        validators=[validators.name_validator],
        error_messages={'required': 'Please enter your first name.'},
    )
    last_name = forms.CharField(
        label='Last Name',
        max_length=30,
        validators=[validators.name_validator],
        error_messages={'required': 'Please enter your last name.'},
    )
    email = forms.EmailField(label='Email Address', validators=[validators.email_validator])


class EditUserDetailsForm(forms.ModelForm):
    """subform for EditProfileForm (below) to handle the UserDetails portion."""
    class Meta:
        model = UserDetails
        fields = ['middle_name', 'zip_code', 'birthdate', 'gender', 'is_organ_donor']

    state = forms.ChoiceField(
        label='State of Residence',
        choices=((state.name, state.title) for state in State.objects.all()),
        required=True,
        error_messages={'required': 'Please select your state.'},
    )

    def save(self, commit=True):
        instance = super(forms.ModelForm, self).save(commit=False)
        state = State.objects.filter(name=self.cleaned_data['state']).first()
        if state is None:
            raise ValueError("State not found: %s" % self.cleaned_data['state'])
        instance.state = state
        if commit == True:
            instance.save()
        return instance


class EditProfileForm(MergedModelForm):
    """form for the edit_profile view."""
    class Meta:
        forms = [EditUserForm, EditUserDetailsForm]
{'fraction_non_alphanumeric': 0.11467522052927025, 'fraction_numerical': 0.002673082063619353, 'mean_word_length': 3.1577777777777776, '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': '776995', 'n_tokens_mistral': 1050, 'n_tokens_neox': 1044, 'n_words': 269}