<commit_before>from django import forms
from django.utils import timezone
from django.core.validators import validate_email
from .models import Sweep, SweepEntry

class SweepEntryForm(forms.Form):

    first_name = forms.CharField(max_length=30, required=True)
    last_name = forms.CharField(max_length=30, required=True)
    email = forms.CharField(required=True)
    date_of_birth = forms.DateField(required=True, widget=forms.TextInput(attrs={'placeholder': 'mm/dd/yyyy'}))
    zip_code = forms.CharField(max_length=10, required=True)
    gender = forms.ChoiceField(choices=[(0, 'Choose your gender')] + SweepEntry.GENDER_CHOICES)
    receive_email = forms.BooleanField(required=False)

    def __init__(self, *args, **kwargs):
        """
        Notice how we need to call __init__ from superclass first, if we don't do this
        then we won't be able to access attributes such as fields and instance.
        """
        super(SweepEntryForm, self).__init__(*args, **kwargs)
        if self.initial:
            self.sweep = self.initial['sweep']

    def save(self):
        sweepentry = SweepEntry(
                        sweep=self.sweep,
                        first_name=self.cleaned_data['first_name'],
                        last_name=self.cleaned_data['last_name'],
                        email=self.cleaned_data['email'],
                        date_of_birth=self.cleaned_data['date_of_birth'],
                        zip_code=self.cleaned_data['zip_code'],
                        gender=self.cleaned_data['gender'],
                        receive_email=self.cleaned_data['receive_email'],
                     )

        sweepentry.save()
        return sweepentry
<commit_msg>complete the initial sweeps app<commit_after>from django import forms
from django.utils import timezone
from django.core.validators import validate_email
from .models import Sweep, SweepEntry

class SweepEntryForm(forms.Form):

    email = forms.CharField(required=True)
    date_of_birth = forms.DateField(required=True, widget=forms.TextInput(attrs={'placeholder': 'mm/dd/yyyy'}))
    first_name = forms.CharField(max_length=30, required=True)
    last_name = forms.CharField(max_length=30, required=True)
    gender = forms.ChoiceField(choices=[(0, 'Choose your gender')] + SweepEntry.GENDER_CHOICES)
    zip_code = forms.CharField(max_length=10, required=True)
    receive_email = forms.BooleanField(required=False)

    def __init__(self, *args, **kwargs):
        """
        Notice how we need to call __init__ from superclass first, if we don't do this
        then we won't be able to access attributes such as fields and instance.
        """
        super(SweepEntryForm, self).__init__(*args, **kwargs)
        if self.initial:
            self.sweep = self.initial['sweep']

    def save(self):
        sweepentry = SweepEntry(
                        sweep=self.sweep,
                        first_name=self.cleaned_data['first_name'],
                        last_name=self.cleaned_data['last_name'],
                        email=self.cleaned_data['email'],
                        date_of_birth=self.cleaned_data['date_of_birth'],
                        zip_code=self.cleaned_data['zip_code'],
                        gender=self.cleaned_data['gender'],
                        receive_email=self.cleaned_data['receive_email'],
                     )

        sweepentry.save()
        return sweepentry

{'fraction_non_alphanumeric': 0.10210035005834306, 'fraction_numerical': 0.004084014002333722, 'mean_word_length': 2.575599582898853, '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': '7529324', 'n_tokens_mistral': 1016, 'n_tokens_neox': 957, 'n_words': 196}