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

gcivil-nyu-org / INET-Wednesday-Spring2024-Team-2 / 155

13 Mar 2024 03:58AM UTC coverage: 70.4%. Remained the same
155

cron

travis-pro

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

first pull from develop into master

174 of 246 new or added lines in 12 files covered. (70.73%)

2 existing lines in 2 files now uncovered.

176 of 250 relevant lines covered (70.4%)

0.7 hits per line

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

70.45
/users/forms.py
1
from django import forms
1✔
2
from django.contrib.auth.forms import UserCreationForm
1✔
3
from django.contrib.auth import get_user_model
1✔
4
from .models import CustomUser
1✔
5
from django.contrib.auth.forms import AuthenticationForm
1✔
6
from django.core.exceptions import ValidationError
1✔
7

8
User = get_user_model()
1✔
9

10

11
class UserSignUpForm(UserCreationForm):
1✔
12
    full_name = forms.CharField(max_length=255, required=True)
1✔
13
    phone_number = forms.CharField(max_length=15, required=True)
1✔
14
    city = forms.CharField(max_length=100, required=True)
1✔
15
    email = forms.EmailField(required=True)
1✔
16

17
    class Meta:
1✔
18
        model = User
1✔
19
        fields = (
1✔
20
            "email",
21
            "full_name",
22
            "phone_number",
23
            "city",
24
            "password1",
25
            "password2",
26
        )
27
    def clean_email(self):
28
        email = self.cleaned_data['email']
1✔
29
        if not email.endswith('@nyu.edu'):
1✔
30
            raise ValidationError("Oops!! Only NYU email addresses are supported.")
1✔
NEW
31
        return email
×
32

1✔
33

34
class LandlordSignupForm(UserCreationForm):
35
    pdf_file = forms.FileField(required=False)
1✔
36

1✔
37
    class Meta:
38
        model = CustomUser
1✔
39
        fields = (
1✔
40
            "username",
1✔
41
            "email",
42
            "full_name",
43
            "phone_number",
44
            "city",
45
            "password1",
46
            "password2",
47
            # "user_type",
48
            "pdf_file",
49
        )
50

51
    # def _init_(self, *args, **kwargs):
52
    #     super(LandlordSignupForm, self)._init_(*args, **kwargs)
53
    #     self.fields["user_type"].initial = CustomUser.LANDLORD
54
    #     self.fields[
55
    #         "user_type"
56
    #     ].widget = forms.HiddenInput()  # Hide the user_type field
57

58
    def _init_(self, *args, **kwargs):
59
        super(LandlordSignupForm, self)._init_(*args, **kwargs)
1✔
NEW
60
        # No need to set user_type initial value here, as it will be set in save.
×
61

62
    def save(self, commit=True):
63
        user = super(LandlordSignupForm, self).save(commit=False)
1✔
NEW
64
        user.user_type = CustomUser.LANDLORD  # Set user_type to LANDLORD
×
NEW
65

×
66
        if commit:
NEW
67
            user.save()
×
NEW
68
            self.save_m2m()  # Call save_m2m if there are many-to-many fields that need to be saved.
×
NEW
69

×
70
        return user
NEW
71
class PasswordResetForm(forms.Form):
×
72
    email = forms.EmailField(label="Email", max_length=254)
73

74
    def clean_email(self):
1✔
75
        email = self.cleaned_data.get('email')
1✔
76
        if not User.objects.filter(email=email).exists():
77
            raise forms.ValidationError("""This email does not exist in our records.
1✔
NEW
78
                                        Please make sure you entered it correctly,
×
NEW
79
                                        or sign up for a new account
×
NEW
80
                                        if you haven't already.""")
×
81
        return email
82

83

84
class CustomLoginForm(AuthenticationForm):
85
    def __init__(self, *args, **kwargs):
NEW
86
        super().__init__(*args, **kwargs)
×
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