-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
71 lines (55 loc) · 2.29 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Customized forms for view/html files"""
from django import forms
from django.core.validators import MaxValueValidator, MinValueValidator
from django.contrib.auth.forms import UserCreationForm, PasswordResetForm, PasswordChangeForm
from .models import Member
#pylint: disable=too-many-ancestors
class RegisterForm(UserCreationForm):
"""Register user form"""
email = forms.EmailField(required=True)
username = forms.CharField(required=True)
latitude = forms.FloatField(
validators=[MinValueValidator(-90.0), MaxValueValidator(90.0)],
)
longitude = forms.FloatField(
validators=[MinValueValidator(-180.0), MaxValueValidator(180.0)]
)
class Meta:
"""Meta class to specify db model"""
model = Member
fields = ("username", "email", "password1", "password2", "latitude", "longitude")
def save(self, commit=True):
user = super().save(commit=False)
user.email = self.cleaned_data["email"]
user.username = self.cleaned_data["username"]
user.latitude = self.cleaned_data["latitude"]
user.longitude = self.cleaned_data["longitude"]
if commit:
user.save()
return user
class ResendVerificationForm(forms.Form):
"""Resend verification email form"""
email = forms.EmailField(required=True)
class LoginForm(forms.Form):
"""Login form"""
username = forms.CharField(label="Username or email")
password = forms.CharField(label="Password", widget=forms.PasswordInput())
class ChangeEmailForm(forms.Form):
"""Change email form"""
email = forms.EmailField(label="New email address", required=True)
email_confirm = forms.EmailField(label="Confirm the new email address", required=True)
class ChangePasswordForm(PasswordChangeForm):
"""Change password form"""
class Meta:
"""Meta class to specify db model"""
model = Member
class ForgotPasswordForm(PasswordResetForm):
"""Reset password form"""
class Meta:
"""Meta class to specify db model"""
model = Member
class DeleteAccountForm(forms.Form):
"""Delete account form"""
username = forms.CharField(label="Username")
challenge = forms.CharField(label='Type "delete my account" to confirm')
password = forms.CharField(label="Password", widget=forms.PasswordInput())