<commit_before>
from datetime import date

from django import forms
from django.forms.extras import SelectDateWidget

from forms_builder.models import BuiltForm, BuiltFormSubmission
from forms_builder.utils import form_builder_optional_fields


class DobWidget(SelectDateWidget):
	"""
	populate the years of a SelectDateWidget for selecting dob
	"""
	
	def __init__(self, attrs=None):
		year = date.today().year
		self.attrs = attrs
		self.years = range(year, year - 100, -1)
		super(SelectDateWidget, self).__init__()


def get_built_form_form(built_form):
	"""
	return a model form for a BuiltFormSubmission, excluding the extra
	fields that haven't been selected as optional or mandatory for the given 
	BuiltForm, and setting the extra mandatory fields that have been selected 
	as mandatory fields
	"""
	
	dob_field = None
	extra_fields = (built_form.extra_fields("mandatory") + 
		built_form.extra_fields("optional"))
	if "dob" in extra_fields:
		dob_field = forms.DateField(widget=DobWidget)

	class BuiltFormForm(forms.ModelForm):
	
		class Meta:
			model = BuiltFormSubmission
			exclude = ["submission_date","built_form"] + [field[0] for field in 
				form_builder_optional_fields() if field[0] not in extra_fields]
			
		dob = dob_field
		
		def __init__(self, *args, **kwargs):
			super(BuiltFormForm, self).__init__(*args, **kwargs)
			for field in built_form.extra_fields("mandatory"):
				self.fields[field].required = True

	return BuiltFormForm<commit_msg>removed empty initial choice from fields with choices that are selected as a mandatory field<commit_after>
from datetime import date

from django import forms
from django.forms.extras import SelectDateWidget

from forms_builder.models import BuiltForm, BuiltFormSubmission
from forms_builder.utils import form_builder_optional_fields


class DobWidget(SelectDateWidget):
	"""
	populate the years of a SelectDateWidget for selecting dob
	"""
	
	def __init__(self, attrs=None):
		year = date.today().year
		self.attrs = attrs
		self.years = range(year, year - 100, -1)
		super(SelectDateWidget, self).__init__()


def get_built_form_form(built_form):
	"""
	return a model form for a BuiltFormSubmission, excluding the extra
	fields that haven't been selected as optional or mandatory for the given 
	BuiltForm, and setting the extra mandatory fields that have been selected 
	as mandatory fields
	"""
	
	dob_field = None
	extra_fields = (built_form.extra_fields("mandatory") + 
		built_form.extra_fields("optional"))
	if "dob" in extra_fields:
		dob_field = forms.DateField(widget=DobWidget)

	class BuiltFormForm(forms.ModelForm):
	
		class Meta:
			model = BuiltFormSubmission
			exclude = ["submission_date","built_form"] + [field[0] for field in 
				form_builder_optional_fields() if field[0] not in extra_fields]
			
		dob = dob_field
		
		def __init__(self, *args, **kwargs):
			super(BuiltFormForm, self).__init__(*args, **kwargs)
			for field in built_form.extra_fields("mandatory"):
				self.fields[field].required = True
				if hasattr(self.fields[field], "choices"):
					self.fields[field].choices = self.fields[field].choices[1:]

	return BuiltFormForm
{'fraction_non_alphanumeric': 0.09021357985336309, 'fraction_numerical': 0.004144086707044948, 'mean_word_length': 5.0, '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': '1034796', 'n_tokens_mistral': 1039, 'n_tokens_neox': 940, 'n_words': 280}