xmpp.chapril.org-conversejs/accounts/forms.py

54 lines
1.7 KiB
Python
Raw Normal View History

2012-03-02 16:16:20 +01:00
from django import forms
2012-03-05 10:55:21 +01:00
from django.utils.translation import ugettext_lazy as _
2012-03-02 16:16:20 +01:00
from accounts.models import Profile
2012-03-02 16:38:41 +01:00
from django.contrib.auth.models import User
2012-03-06 15:15:28 +01:00
from registration.forms import RegistrationFormUniqueEmail
2012-03-02 16:16:20 +01:00
class ProfileForm(forms.ModelForm):
class Meta:
model = Profile
exclude = [
'suggested',
'translated',
]
2012-03-02 16:38:41 +01:00
class UserForm(forms.ModelForm):
class Meta:
model = User
fields = [
'first_name',
'last_name',
'email',
]
2012-03-05 10:55:21 +01:00
2012-03-05 11:44:26 +01:00
class ContactForm(forms.Form):
subject = forms.CharField(label = _('Subject'), required = True)
2012-03-05 11:46:50 +01:00
name = forms.CharField(label = _('Your name'), required = True)
email = forms.EmailField(label = _('Your email'), required = True)
2012-03-05 11:44:26 +01:00
message = forms.CharField(
2012-03-05 10:55:21 +01:00
label = _('Message'),
required = True,
widget = forms.Textarea
)
2012-03-06 15:15:28 +01:00
class RegistrationForm(RegistrationFormUniqueEmail):
first_name = forms.CharField(label = _('First name'))
last_name = forms.CharField(label = _('Last name'))
def __init__(self, *args, **kwargs):
super(RegistrationForm, self).__init__(*args, **kwargs)
self.fields['username'].label = _('Username')
self.fields['email'].label = _('Email address')
self.fields['password1'].label = _('Password')
self.fields['password2'].label = _('Password (again)')
def save(self, *args, **kwargs):
new_user = super(RegistrationForm, self).save(*args, **kwargs)
new_user.first_name = self.cleaned_data['first_name']
new_user.last_name = self.cleaned_data['last_name']
new_user.save()
return new_user