# 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
    def clean_to_date(self):
        cleaned_data = super(EffQueryForm, self).clean()
        from_date = cleaned_data.get('from_date')
        to_date = cleaned_data.get('to_date')
        if to_date < from_date:
            raise forms.ValidationError("This date should be greater")

        return to_date


class UserProfileForm(ModelForm):
    """ Combines data from UserProfile """

    def __init__(self, *args, **kwargs):
        super(UserProfileForm, self).__init__(*args, **kwargs)
        try:
            self.fields['first_name'].initial = self.instance.user.first_name
            self.fields['last_name'].initial = self.instance.user.last_name
        except User.DoesNotExist:
            pass

    def save(self, *args, **kwargs):
        u = self.instance.user
        u.first_name = self.cleaned_data['first_name']
        u.last_name = self.cleaned_data['last_name']
        u.save()
        profile = super(UserProfileForm, self).save(*args, **kwargs)
        return profile

    class Meta:

# 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

    def clean_to_date(self):
        cleaned_data = super(EffQueryForm, self).clean()
        from_date = cleaned_data.get('from_date')
        to_date = cleaned_data.get('to_date')
        if to_date < from_date:
            raise forms.ValidationError("This date should be greater")

        return to_date


class UserProfileForm(ModelForm):
    """ Combines data from UserProfile """

    def __init__(self, *args, **kwargs):
        super(UserProfileForm, self).__init__(*args, **kwargs)
        try:
            self.fields['first_name'].initial = self.instance.user.first_name
            self.fields['last_name'].initial = self.instance.user.last_name
        except User.DoesNotExist:
            pass

    def save(self, *args, **kwargs):
        u = self.instance.user
        u.first_name = self.cleaned_data['first_name']
        u.last_name = self.cleaned_data['last_name']
        u.save()
        profile = super(UserProfileForm, self).save(*args, **kwargs)
        return profile

    class Meta:

        model = UserProfile