# Path: eff_site/eff/models.py



from django import forms
from django.forms import ModelForm
from django.contrib.auth.models import User, Group
from django.contrib.auth.forms import UserCreationForm
from django.forms.util import ErrorList
from eff_site.eff.models import UserProfile, Client, AvgHours, Wage


class UserAddForm(forms.Form):
    """ Add user """
    username = forms.CharField(max_length=100, label='Username')
    password = forms.CharField(max_length=100, widget=forms.PasswordInput,
                               label='Password')
    password2 = forms.CharField(max_length=100, widget=forms.PasswordInput,
                                label='Password confirmation')

    def clean(self):
        password2 = self.cleaned_data.get('password2')
        password = self.cleaned_data.get('password')

        if password is None and password2 is None:
            return self.cleaned_data

        if password is not None and password2 != password:
            raise forms.ValidationError('The two passwords do not match.')

        try:
            if User.objects.get(username=self.cleaned_data.get('username')):
                raise forms.ValidationError('User already exists.')
        except User.DoesNotExist:
            pass
        return self.cleaned_data


class ClientReportForm(EffQueryForm):
    """ Admin to generate client reports """

# Path: eff_site/eff/models.py



# Path: eff_site/eff/forms.py
from django import forms
from django.forms import ModelForm
from django.contrib.auth.models import User, Group
from django.contrib.auth.forms import UserCreationForm
from django.forms.util import ErrorList
from eff_site.eff.models import UserProfile, Client, AvgHours, Wage



class UserAddForm(forms.Form):
    """ Add user """
    username = forms.CharField(max_length=100, label='Username')
    password = forms.CharField(max_length=100, widget=forms.PasswordInput,
                               label='Password')
    password2 = forms.CharField(max_length=100, widget=forms.PasswordInput,
                                label='Password confirmation')

    def clean(self):
        password2 = self.cleaned_data.get('password2')
        password = self.cleaned_data.get('password')

        if password is None and password2 is None:
            return self.cleaned_data

        if password is not None and password2 != password:
            raise forms.ValidationError('The two passwords do not match.')

        try:
            if User.objects.get(username=self.cleaned_data.get('username')):
                raise forms.ValidationError('User already exists.')
        except User.DoesNotExist:
            pass
        return self.cleaned_data


class ClientReportForm(EffQueryForm):
    """ Admin to generate client reports """

    client = forms.ModelChoiceField(queryset=Client.objects.all(),