"""
Created on 03.10.2011

@author: christian
"""
from django import forms
from django.utils.translation import ugettext as _
from django.contrib.auth import get_user_model

from . import models
from utils.html5.widgets import DateTimeInput


user_query = get_user_model().objects.all()


class PhotoUploadForm(forms.Form):
    error_css_class = 'error'
    required_css_class = 'required'
    photographer = forms.ModelChoiceField(user_query, required=True, )
    event = forms.ModelChoiceField(models.Event.objects.all(), required=True, )
    upload = forms.FileField(
        label=_('Images'),
        required=True,
        widget=forms.widgets.ClearableFileInput(
            attrs={
                'multiple': 'multiple',
                'accept': "image/gif,image/png,image/jpeg"
            }
        )
    )


class EditPhotoForm(forms.ModelForm):
    error_css_class = 'error'
    required_css_class = 'required'

    class Meta(object):
        model = models.Photo
        fields = ('event', 'name', 'description', 'photographer',
                  'anchor_horizontal', 'anchor_vertical',
                  'created_date', 'on_startpage')


class EventForm(forms.ModelForm):
    error_css_class = 'error'
    required_css_class = 'required'

    start = forms.DateTimeField(
        label=_('start'), required=True,
        widget=DateTimeInput()  # widget=SplitDateTimeWidget()
    )
    end = forms.DateTimeField(
        label=_('end'), required=False,
        widget=DateTimeInput()  # widget=SplitDateTimeWidget()
    )

    class Meta(object):
        model = models.Event
        exclude = ('event_count', 'event_series', )

EventSeriesFormset = forms.inlineformset_factory(models.Event, models.Event, fields=('start', 'end'), form=EventForm)