from django.forms import ModelForm
from django import forms
from models import *

from form_utils.forms import BetterModelForm

class TheoryExamFormForm(ModelForm):

    class Meta:
        model = TheoryExamForm
        fields = ('name','introduction','payment_amount','type','enabled')


class ExamLocationForm(ModelForm):

    class Meta:
        model = ExamLocation
        exclude = ('exam_form',)

class ExamChoiceForm(ModelForm):

    class Meta:
        model = ExamChoice
        exclude = ('exam_form',)


class TheoryApplicantDetailsFormResit(BetterModelForm):

    def __init__(self,*args,**kwargs):
        super(TheoryApplicantDetailsFormResit,self).__init__(*args,**kwargs)
        self.fields['title'].required = True
        self.fields['first_name'].required = True
        self.fields['surname'].required = True
        self.fields['email_address'].required = True
        self.fields['contact_number'].required = True
        self.fields['dob'].required = True
        self.fields['job_title'].required = True
        self.fields['current_employer'].required = True
        self.fields['employment_start_date'].required = True
        self.fields['work_address_1'].required = True
        self.fields['work_town'].required = True
        self.fields['work_county'].required = True
        self.fields['work_postcode'].required = True
        self.fields['work_country'].required = True
        self.fields['exam_choices'].required = True
        self.fields['exam_choices'].label = ''

    class Meta:
        model = TheoryExamApplication
        fieldsets = [
            ('personal_details',{'fields': ['membership_number','title','first_name','surname','email_address','contact_number','dob'],'legend':'Personal Details','description':'Applicants for the theory exam must be an ordinary member of the SVT.'}),
            ('employment',{'fields': ['job_title','current_employer','employment_start_date'],'legend':'Employment','description':'Applicants for the theory exam must be currently employed in the UK or ireland to perform vascular diagnostic investigations.'}),
            ('work_address',{'fields': ['work_address_1','work_address_2','work_town','work_county','work_postcode','work_country'],'legend':'Work Address',}),
            ('mailing_address',{'fields': ['mailing_address_1','mailing_address_2','mailing_town','mailing_county','mailing_postcode','mailing_country'],'legend':'Mailing Address'}),
            ('exam_choices',{'fields':['exam_choices'],'legend':'Exam Choice','description':'Which exam(s) would you like to sit?'}),
        ]
        widgets = {
            'exam_choices' : forms.CheckboxSelectMultiple(),
        }


class TheoryApplicantDetailsForm(TheoryApplicantDetailsFormResit):

    class Meta:
        model = TheoryExamApplication
        fieldsets = [
            ('personal_details',{'fields': ['membership_number','title','first_name','surname','email_address','contact_number','dob'],'legend':'Personal Details','description':'Applicants for the theory exam must be an ordinary member of the SVT.'}),
            ('employment',{'fields': ['job_title','current_employer','employment_start_date'],'legend':'Employment','description':'Applicants for the theory exam must be currently employed in the UK or ireland to perform vascular diagnostic investigations.'}),
            ('work_address',{'fields': ['work_address_1','work_address_2','work_town','work_county','work_postcode','work_country'],'legend':'Work Address',}),
            ('mailing_address',{'fields': ['mailing_address_1','mailing_address_2','mailing_town','mailing_county','mailing_postcode','mailing_country'],'legend':'Mailing Address'}),
            ('exam_choices',{'fields':['exam_choices'],'legend':'Exam Choice','description':'Which exam would you like to sit?'}),
        ]
        widgets = {
            'exam_choices' : forms.CheckboxSelectMultiple(),
        }
