<commit_before>import datetime

from django import forms
from django.conf import settings
from django.contrib.auth import forms as auth_forms
from django.forms.extras import widgets
from django.utils import safestring
from django.utils.translation import ugettext_lazy as _

from piplmesh.account import fields, form_fields, models

class HorizontalRadioRenderer(forms.RadioSelect.renderer):
    """
    Renders horizontal radio buttons.
    Found `here 
    <https://wikis.utexas.edu/display/~bm6432/Django-Modifying+RadioSelect+Widget+to+have+horizontal+buttons>`_.
    """

    def render(self):
        return safestring.mark_safe(u'\n'.join([u'%s\n' % widget for widget in self]))

class RegistrationForm(auth_forms.UserCreationForm):
    """
    Class with user registration form.
    """

    # Required data
    email = forms.EmailField(label=_("E-mail"))
    first_name = forms.CharField(label=_("First name"))
    last_name = forms.CharField(label=_("Last name"))
    
    # Additional information
    gender = forms.ChoiceField(
        label=_("Gender"),
        required=False,
        choices=fields.GENDER_CHOICES,
        widget=forms.RadioSelect(renderer=HorizontalRadioRenderer),
    )    
    birthdate = form_fields.LimitedDateTimeField(
        upper_limit=datetime.datetime.today(),
        lower_limit=datetime.datetime.today() - datetime.timedelta(models.LOWER_DATE_LIMIT),
        label=_("Birth date"),
        required=False,
        widget=widgets.SelectDateWidget(
            years=[
                y for y in range(
                    datetime.datetime.today().year,
                    (datetime.datetime.today() - datetime.timedelta(models.LOWER_DATE_LIMIT)).year,
                    -1,
                )
            ],
        ),
    )
    
    def clean_password2(self):<commit_msg>Radio widgets rendering in registration form.<commit_after>import datetime

from django import forms
from django.conf import settings
from django.contrib.auth import forms as auth_forms
from django.forms import widgets
from django.forms.extras import widgets as extras_widgets
from django.utils import encoding, safestring
from django.utils.translation import ugettext_lazy as _

from piplmesh.account import fields, form_fields, models

class RadioFieldRenderer(widgets.RadioFieldRenderer):
    """
    RadioSelect renderer which adds ``first`` and ``last`` style classes
    to first and last radio widgets.
    """

    def _render_widgets(self):
        for i, w in enumerate(self):
            classes = []
            if i == 0:
                classes.append('first')
            if i == len(self.choices) - 1:
                classes.append('last')

            cls = ''
            if classes:
                cls = u' class="%s"' % (u' '.join(classes),)

            yield u'<li%s>%s</li>' % (cls, encoding.force_unicode(w))

    def render(self):
        return safestring.mark_safe(u'<ul>\n%s\n</ul>' % (u'\n'.join(self._render_widgets())),)

class RegistrationForm(auth_forms.UserCreationForm):
    """
    Class with user registration form.
    """

    # Required data
    email = forms.EmailField(label=_("E-mail"))
    first_name = forms.CharField(label=_("First name"))
    last_name = forms.CharField(label=_("Last name"))
    
    # Additional information
    gender = forms.ChoiceField(
        label=_("Gender"),
        required=False,
        choices=fields.GENDER_CHOICES,
        widget=forms.RadioSelect(renderer=RadioFieldRenderer),
    )    
    birthdate = form_fields.LimitedDateTimeField(
        upper_limit=datetime.datetime.today(),
        lower_limit=datetime.datetime.today() - datetime.timedelta(models.LOWER_DATE_LIMIT),
        label=_("Birth date"),
        required=False,
        widget=extras_widgets.SelectDateWidget(
            years=[
                y for y in range(
                    datetime.datetime.today().year,
                    (datetime.datetime.today() - datetime.timedelta(models.LOWER_DATE_LIMIT)).year,
                    -1,
                )
            ],
        ),
    )
    
    def clean_password2(self):
{'fraction_non_alphanumeric': 0.10951219512195122, 'fraction_numerical': 0.0024390243902439024, 'mean_word_length': 2.622791519434629, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 1, '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': '578178', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1146, 'n_words': 242}