diff options
author | Filipp Lepalaan <f@230.to> | 2013-11-17 19:15:30 +0200 |
---|---|---|
committer | Filipp Lepalaan <f@230.to> | 2013-11-17 19:15:30 +0200 |
commit | 297419f370ea87458017ee506a2e551e9068b66b (patch) | |
tree | 429d3e1b6c7f2facfb3e361b4b708f0d36e8aac8 /apps/core/forms.py | |
parent | f077badf3163fc36c111dc45fe8d7d6f57d8712a (diff) | |
download | motor.old-297419f370ea87458017ee506a2e551e9068b66b.tar.gz motor.old-297419f370ea87458017ee506a2e551e9068b66b.tar.bz2 motor.old-297419f370ea87458017ee506a2e551e9068b66b.zip |
Swicthing machines
Diffstat (limited to 'apps/core/forms.py')
-rw-r--r-- | apps/core/forms.py | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/apps/core/forms.py b/apps/core/forms.py index 66a6287..051663b 100644 --- a/apps/core/forms.py +++ b/apps/core/forms.py @@ -1,12 +1,43 @@ from django import forms +from django.contrib import auth +from apps.core.models import ServiceProvider, User +from django.forms.extras.widgets import SelectDateWidget class LoginForm(forms.Form): - username = forms.CharField(widget=forms.TextInput(attrs={ - 'class': 'form-control', - 'placeholder': 'Email address' - })) - password = forms.CharField(widget=forms.PasswordInput(attrs={ - 'class': 'form-control', - 'placeholder': 'password' - })) + username = forms.CharField() + password = forms.CharField(widget=forms.PasswordInput()) + + def clean(self): + cleaned_data = super(LoginForm, self).clean() + user = auth.authenticate( + username=cleaned_data['username'], + password=cleaned_data['password'] + ) + if user is not None and user.is_active: + cleaned_data['user'] = user + else: + raise forms.ValidationError('Incorrect username or password') + + return cleaned_data + + +class EditProviderForm(forms.ModelForm): + class Meta: + model = ServiceProvider + widgets = { + 'date_started': SelectDateWidget(), + 'date_ends': SelectDateWidget() + } + + +class ProfileEditForm(forms.ModelForm): + class Meta: + model = User + fields = ('first_name', 'last_name', 'email') + + +class UserEditForm(forms.ModelForm): + class Meta: + model = User + exclude = ('groups', 'user_permissions') |