"""Django Forms to administrate the event content on the frontend."""
from django import forms
from django.contrib.auth import get_user_model
from django.utils.translation import ugettext as _

from . import models


class PhotoUploadForm(forms.Form):
    """Form to upload multiple photos to a single event."""
    error_css_class = 'error'
    required_css_class = 'required'
    photographer = forms.ModelChoiceField(get_user_model().objects.all(),
                                          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):
    """From to edit the metadata of a photo."""
    error_css_class = 'error'
    required_css_class = 'required'

    class Meta(object):
        """Metadata to localize and customize the ModelForm."""
        model = models.Photo
        fields = ('event', 'name', 'description', 'photographer',
                  'created_date', 'on_startpage')


class EventForm(forms.ModelForm):
    """Form to add or edit an event."""
    error_css_class = 'error'
    required_css_class = 'required'

    start = forms.SplitDateTimeField(
        label=_('start'), required=True,
    )
    end = forms.SplitDateTimeField(
        label=_('end'), required=False,
    )

    class Meta(object):
        """Metadata to localize and customize the ModelForm."""
        model = models.Event
        exclude = ('event_count', 'event_series',)


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