import floppyforms as forms
from models import *
from app.forms import *
from itfprofiles.models import Person, TheatreGroup

class PersonEventForm(ItfForm):
    person = forms.ModelChoiceField(Person.objects.all(), widget=AutocompleteAddWidget(model_class=Person))

    class Meta:
        model = PersonEvent


class GroupEventForm(ItfForm):
    group = forms.ModelChoiceField(TheatreGroup.objects.all(), widget=AutocompleteAddWidget(model_class=TheatreGroup))

    class Meta:
        model = GroupEvent


PersonEventInline = itf_inlineformset_factory(Event, PersonEvent, form=PersonEventForm, extra=1, title="Add / Edit people associated with this event", help_text="select the people that are connected to this event")

GroupEventInline = itf_inlineformset_factory(Event, GroupEvent, form=GroupEventForm, extra=1, title="Add / Edit groups associated with this event", help_text="select the groups that are connected to this event")


class EventForm(ItfForm):
    inlines = [PersonEventInline, GroupEventInline]
    
    class Meta:
        model = Event
        exclude = ('people', 'groups',)
