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

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

01 Apr 2024 04:01AM UTC coverage: 81.553% (-8.1%) from 89.701%
234

cron

travis-pro

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

merging latest develop into master

104 of 159 new or added lines in 7 files covered. (65.41%)

8 existing lines in 3 files now uncovered.

336 of 412 relevant lines covered (81.55%)

0.82 hits per line

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

87.18
/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

28
    def clean_email(self):
1✔
29
        email = self.cleaned_data["email"]
1✔
30
        if not email.endswith("@nyu.edu"):
1✔
NEW
31
            raise ValidationError("Oops! Only NYU email addresses are supported.")
×
32
        if User.objects.filter(username=self.cleaned_data["email"]).exists():
1✔
NEW
33
            raise ValidationError("Email already exists. Please use a different one.")
×
34
        return email
1✔
35

36

37
class LandlordSignupForm(UserCreationForm):
1✔
38
    pdf_file = forms.FileField(required=False, label="OwnerShip Document")  #
1✔
39

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

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

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

65
    def save(self, commit=True):
1✔
66
        user = super(LandlordSignupForm, self).save(commit=False)
1✔
67
        user.user_type = CustomUser.LANDLORD  # Set user_type to LANDLORD
1✔
68

69
        if commit:
1✔
UNCOV
70
            user.save()
×
NEW
71
            self.save_m2m()
×
72

73
        return user
1✔
74

75

76
class CustomLoginForm(AuthenticationForm):
1✔
77
    def __init__(self, *args, **kwargs):
1✔
78
        super().__init__(*args, **kwargs)
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