from django.forms import ModelForm, Form, Textarea, CharField, ModelChoiceField, ChoiceField
from mblog.models import BloggerProfile, Visitor, Thematic, Post, Comment
from django.contrib.auth.models import User


class VisitorForm(ModelForm):
    class Meta:
        model = Visitor
        fields = ['username']


class CommentForm(ModelForm):
    class Meta:
        model = Comment
        fields = ['text']
        widgets = {'text': Textarea(attrs={'cols': 30, 'rows': 3})}


class BloggerForm(ModelForm):
    input_info = CharField(widget=Textarea(attrs={'cols': 80, 'rows': 20}))

    class Meta:
        model = BloggerProfile
        fields = ['image', 'input_info']


class PostForm(ModelForm):
    input_text = CharField(widget=Textarea(attrs={'cols': 80, 'rows': 20}))

    class Meta:
        model = Post
        fields = ['title', 'input_text', 'thematic']


class SearchForm(Form):
    months = [('', ''),
              (1, 'January'),
              (2, 'February'),
              (3, 'March'),
              (4, 'April'),
              (5, 'May'),
              (6, 'June'),
              (7, 'July'),
              (8, 'August'),
              (9, 'September'),
              (10, 'October'),
              (11, 'November'),
              (12, 'December')]

    month = ChoiceField(required=False, choices=months)
    year = ChoiceField(required=False, choices=[('', ''), (2015, '2015'), (2014, '2014'), (2013, '2013')])
    blogger = ModelChoiceField(required=False, queryset=User.objects.all().exclude(username='admin'), empty_label='')
    thematic = ModelChoiceField(required=False, queryset=Thematic.objects.all(), empty_label='')
    search = CharField(required=False)