from django import forms
from django.contrib.auth.models import User

from .models import Event

from datetime import date

class EventForm(forms.ModelForm):
    class Meta:
        model = Event
        fields = ['movie_title', 'theatre', 'show_time', 'date', 'members', 'owner']


class UserForm(forms.ModelForm):
    password = forms.CharField(widget=forms.PasswordInput)
    class Meta:
        model = User
        fields = ['username', 'email', 'password']

class MovieForm(forms.Form):
    zip = forms.CharField(max_length=5)
    startDate = forms.DateField(widget=forms.SelectDateWidget)
    movie_title = forms.ChoiceField(widget=forms.Select, required=False)
    theatre = forms.ChoiceField(widget=forms.Select, required=False)
    show_time = forms.ChoiceField(widget=forms.Select, required=False)

    def clean_startDate(self):
        data = self.cleaned_data['startDate']
        present = date.today()
        if data < present:
            raise forms.ValidationError('Enter a date after today and at most 20 days from now')
        return data

