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

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

29 Nov 2023 09:43PM UTC coverage: 85.196% (-2.9%) from 88.099%
#6

push

travis-ci

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

Nov 29 Merge to Production

87 of 123 new or added lines in 11 files covered. (70.73%)

58 existing lines in 5 files now uncovered.

915 of 1074 relevant lines covered (85.2%)

0.85 hits per line

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

94.64
/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
"""
1✔
98
Now in map.forms.py
99

100
 class PostForm(forms.ModelForm):
101
     class Meta:
102
        model = Post
103
        fields = ["title", "post", "created_at"]
104
"""
105

106

107
class UserVerificationForm(forms.ModelForm):
1✔
108
    BUSINESS_TYPES = (
1✔
109
        ("Public Parking Lot Owner", "Public Parking Lot Owner"),
110
        ("Private Parking Lot Owner", "Private Parking Lot Owner"),
111
        ("Street Business Owner", "Street Business Owner"),
112
    )
113
    business_name = forms.CharField(max_length=200)
1✔
114
    business_type = forms.ChoiceField(choices=BUSINESS_TYPES)
1✔
115
    business_address = forms.CharField(max_length=200)
1✔
116
    uploaded_file = forms.FileField(
1✔
117
        label="Choose a file",
118
        required=True,
119
        validators=[
120
            FileExtensionValidator(
121
                allowed_extensions=["pdf", "doc", "docx", "png", "jpg", "jpeg"]
122
            )
123
        ],
124
    )
125

126
    class Meta:
1✔
127
        model = UserVerification
1✔
128
        fields = ["business_name", "business_type", "business_address", "uploaded_file"]
1✔
129

130
    def clean_uploaded_file(self):
1✔
131
        uploaded_file = self.cleaned_data["uploaded_file"]
1✔
132
        if not uploaded_file:
1✔
UNCOV
133
            raise forms.ValidationError("You must upload a file.")
×
134
        return uploaded_file
1✔
135

136

137
class UserPasswordResetForm(PasswordResetForm):
1✔
138
    email = forms.EmailField(
1✔
139
        widget=forms.TextInput(
140
            attrs={
141
                "type": "email",
142
                "class": "form-control",
143
                "placeholder": "name@example.com",
144
            }
145
        )
146
    )
147

148
    email_template_name = "users/password_reset_email.html"
1✔
149
    subject_template_name = "users/password_reset_email_subject.txt"
1✔
150

151
    class Meta:
1✔
152
        fields = ["email"]
1✔
153

154

155
class UserPasswordResetConfirmForm(SetPasswordForm):
1✔
156
    new_password1 = forms.CharField(
1✔
157
        strip=False,
158
        label="New password",
159
        help_text=password_validation.password_validators_help_text_html(),
160
        widget=forms.PasswordInput(
161
            attrs={"class": "form-control", "placeholder": "Enter Password"}
162
        ),
163
    )
164
    new_password2 = forms.CharField(
1✔
165
        strip=False,
166
        label="New password confirmation",
167
        widget=forms.PasswordInput(
168
            attrs={"class": "form-control", "placeholder": "Confirm Password"}
169
        ),
170
    )
171

172
    class Meta:
1✔
173
        fields = ["new_password1", "new_password2"]
1✔
174

175

176
class EditPostForm(forms.ModelForm):
1✔
177
    """edit post form"""
178

179
    title = forms.CharField(
1✔
180
        widget=forms.TextInput(
181
            attrs={
182
                "class": "form-control",
183
                "placeholder": "Post title goes here",
184
            }
185
        )
186
    )
187

188
    post = forms.CharField(
1✔
189
        widget=forms.Textarea(
190
            attrs={"class": "form-control", "placeholder": "Post content goes here"}
191
        )
192
    )
193

194
    class Meta:
1✔
195
        model = Post
1✔
196
        fields = ["title", "post"]
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