• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gcivil-nyu-org / Wednesday-Fall2023-Team-2 / #3

30 Oct 2023 01:44PM UTC coverage: 88.099%. First build
#3

push

travis-ci

web-flow
Merge pull request #59 from gcivil-nyu-org/develop

v1.2

421 of 421 new or added lines in 14 files covered. (100.0%)

607 of 689 relevant lines covered (88.1%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.23
/users/forms.py
1
"""user forms
2

3
Creating Model Forms
4
https://docs.djangoproject.com/en/4.2/topics/forms/modelforms/
5

6
Difference between Model and Forms
7
https://stackoverflow.com/questions/5481713/whats-the-difference-between-django-models-and-forms
8
"""
9

10
from django import forms
1✔
11
from django.contrib.auth import password_validation
1✔
12
from django.contrib.auth.forms import (
1✔
13
    SetPasswordForm,
14
    UserCreationForm,
15
    PasswordResetForm,
16
    AuthenticationForm,
17
)
18

19
from .models import User, Post, UserVerification
1✔
20

21
from django.core.validators import FileExtensionValidator
1✔
22

23

24
class UserLoginForm(AuthenticationForm):
1✔
25
    """login form"""
26

27
    username = forms.CharField(
1✔
28
        widget=forms.TextInput(
29
            attrs={"class": "form-control", "placeholder": "Enter username or email"}
30
        )
31
    )
32

33
    password = forms.CharField(
1✔
34
        widget=forms.PasswordInput(
35
            attrs={"class": "form-control", "placeholder": "Enter password"}
36
        )
37
    )
38

39
    remember_me = forms.BooleanField(
1✔
40
        required=False,
41
        widget=forms.CheckboxInput(
42
            attrs={"class": "form-check-input", "type": "checkbox"}
43
        ),
44
    )
45

46
    def confirm_login_allowed(self, user):
1✔
47
        if not user.is_active:
×
48
            raise forms.ValidationError("This account is inactive.", code="inactive")
×
49

50
    class Meta:
1✔
51
        """_summary_"""
52

53
        model = User
1✔
54
        fields = ["username", "password"]
1✔
55

56

57
class UserRegisterForm(UserCreationForm):
1✔
58
    """user registration form"""
59

60
    username = forms.CharField(
1✔
61
        widget=forms.TextInput(
62
            attrs={"class": "form-control", "placeholder": "Enter username"}
63
        )
64
    )
65

66
    email = forms.EmailField(
1✔
67
        widget=forms.TextInput(
68
            attrs={"class": "form-control", "placeholder": "Enter email"}
69
        )
70
    )
71

72
    """
1✔
73
    avatar = forms.ImageField(
74
        widget = forms.ClearableFileInput(
75
            attrs={"class": "form-control"}
76
        )
77
    )
78
    """
79

80
    password1 = forms.CharField(
1✔
81
        widget=forms.PasswordInput(
82
            attrs={"class": "form-control", "placeholder": "Enter Password"}
83
        )
84
    )
85

86
    password2 = forms.CharField(
1✔
87
        widget=forms.PasswordInput(
88
            attrs={"class": "form-control", "placeholder": "Confirm Password"}
89
        )
90
    )
91

92
    class Meta:
1✔
93
        model = User
1✔
94
        fields = ["username", "email", "password1", "password2"]
1✔
95

96

97
class PostForm(forms.ModelForm):
1✔
98
    class Meta:
1✔
99
        model = Post
1✔
100
        fields = ["title", "post", "created_at"]
1✔
101

102

103
class UserVerificationForm(forms.ModelForm):
1✔
104
    business_name = forms.CharField(max_length=200)
1✔
105
    business_type = forms.CharField(max_length=200)
1✔
106
    business_address = forms.CharField(max_length=200)
1✔
107
    uploaded_file = forms.FileField(
1✔
108
        label="Choose a file",
109
        required=True,
110
        validators=[
111
            FileExtensionValidator(
112
                allowed_extensions=["pdf", "doc", "docx", "png", "jpg", "jpeg"]
113
            )
114
        ],
115
    )
116

117
    class Meta:
1✔
118
        model = UserVerification
1✔
119
        fields = ["business_name", "business_type", "business_address", "uploaded_file"]
1✔
120

121
    def clean_uploaded_file(self):
1✔
122
        uploaded_file = self.cleaned_data["uploaded_file"]
1✔
123
        if not uploaded_file:
1✔
124
            raise forms.ValidationError("You must upload a file.")
×
125
        return uploaded_file
1✔
126

127

128
class UserPasswordResetForm(PasswordResetForm):
1✔
129
    email = forms.EmailField(
1✔
130
        widget=forms.TextInput(
131
            attrs={
132
                "type": "email",
133
                "class": "form-control",
134
                "placeholder": "name@example.com",
135
            }
136
        )
137
    )
138

139
    email_template_name = "users/password_reset_email.html"
1✔
140
    subject_template_name = "users/password_reset_email_subject.txt"
1✔
141

142
    class Meta:
1✔
143
        fields = ["email"]
1✔
144

145

146
class UserPasswordResetConfirmForm(SetPasswordForm):
1✔
147
    new_password1 = forms.CharField(
1✔
148
        strip=False,
149
        label="New password",
150
        help_text=password_validation.password_validators_help_text_html(),
151
        widget=forms.PasswordInput(
152
            attrs={"class": "form-control", "placeholder": "Enter Password"}
153
        ),
154
    )
155
    new_password2 = forms.CharField(
1✔
156
        strip=False,
157
        label="New password confirmation",
158
        widget=forms.PasswordInput(
159
            attrs={"class": "form-control", "placeholder": "Confirm Password"}
160
        ),
161
    )
162

163
    class Meta:
1✔
164
        fields = ["new_password1", "new_password2"]
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc