# Path: console/models.py
# class UwsgiItApi(models.Model):
#     url = models.CharField(max_length=512, unique=True)
#     name = models.CharField(max_length=255, blank=True)
# 
#     def __unicode__(self):
#         return self.url


from datetime import datetime, timedelta
from django import forms
from django.conf import settings
from django.utils.dates import MONTHS
from django.core.validators import validate_email
from django.core.urlresolvers import resolve, Resolver404
from uwsgiit.api import UwsgiItClient
from select2.widgets import SelectMultipleAutocomplete, SelectAutocomplete
from .models import UwsgiItApi
        choices=(),
        required=False)

    def __init__(self, *args, **kwargs):
        tag_choices = kwargs.pop('tag_choices')
        super(TagsForm, self).__init__(*args, **kwargs)
        self.fields['tags'].choices = tag_choices


class BootstrapForm(forms.Form):

    def __init__(self, *args, **kwargs):
        super(BootstrapForm, self).__init__(*args, **kwargs)
        for field in self.fields.keys():
            if not isinstance(self.fields[field].widget, (SelectAutocomplete, SelectMultipleAutocomplete)):
                self.fields[field].widget.attrs['class'] = 'form-control'


class LoginForm(forms.Form):
    action_login = forms.IntegerField(
        label='', widget=forms.HiddenInput(), initial=1)
    username = forms.CharField(label='', widget=forms.TextInput(
        attrs={'class': 'form-control', 'placeholder': 'Username'}))
    password = forms.CharField(label='', widget=forms.PasswordInput(
        attrs={'class': 'form-control', 'placeholder': 'Password'}))
    api_url = forms.ModelChoiceField(
        label='Api url :', queryset=UwsgiItApi.objects.none())

    def __init__(self, *args, **kwargs):
        super(LoginForm, self).__init__(*args, **kwargs)

# Path: console/models.py
# class UwsgiItApi(models.Model):
#     url = models.CharField(max_length=512, unique=True)
#     name = models.CharField(max_length=255, blank=True)
# 
#     def __unicode__(self):
#         return self.url


# Path: console/forms.py
from datetime import datetime, timedelta
from django import forms
from django.conf import settings
from django.utils.dates import MONTHS
from django.core.validators import validate_email
from django.core.urlresolvers import resolve, Resolver404
from uwsgiit.api import UwsgiItClient
from select2.widgets import SelectMultipleAutocomplete, SelectAutocomplete
from .models import UwsgiItApi

        choices=(),
        required=False)

    def __init__(self, *args, **kwargs):
        tag_choices = kwargs.pop('tag_choices')
        super(TagsForm, self).__init__(*args, **kwargs)
        self.fields['tags'].choices = tag_choices


class BootstrapForm(forms.Form):

    def __init__(self, *args, **kwargs):
        super(BootstrapForm, self).__init__(*args, **kwargs)
        for field in self.fields.keys():
            if not isinstance(self.fields[field].widget, (SelectAutocomplete, SelectMultipleAutocomplete)):
                self.fields[field].widget.attrs['class'] = 'form-control'


class LoginForm(forms.Form):
    action_login = forms.IntegerField(
        label='', widget=forms.HiddenInput(), initial=1)
    username = forms.CharField(label='', widget=forms.TextInput(
        attrs={'class': 'form-control', 'placeholder': 'Username'}))
    password = forms.CharField(label='', widget=forms.PasswordInput(
        attrs={'class': 'form-control', 'placeholder': 'Password'}))
    api_url = forms.ModelChoiceField(
        label='Api url :', queryset=UwsgiItApi.objects.none())

    def __init__(self, *args, **kwargs):
        super(LoginForm, self).__init__(*args, **kwargs)

        self.fields['api_url'].queryset = UwsgiItApi.objects.all()