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

gcivil-nyu-org / INT2-Monday-Spring2024-Team-2 / 13

01 Mar 2024 05:17PM UTC coverage: 65.975%. First build
13

push

travis-pro

web-flow
Merge pull request #39 from gcivil-nyu-org/feature/shihui

Set up Travis CI

36 of 69 new or added lines in 7 files covered. (52.17%)

159 of 241 relevant lines covered (65.98%)

0.66 hits per line

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

40.82
/TutorRegister/forms.py
1
from django import forms
1✔
2
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
1✔
3

4
from django.contrib.auth.models import User
1✔
5
from django.core.exceptions import ValidationError
1✔
6

7

8
class RegisterUserForm(UserCreationForm):
1✔
9
    USER_TYPES = (
1✔
10
        ("student", "Student"),
11
        ("tutor", "Tutor"),
12
    )
13

14
    user_type = forms.ChoiceField(
1✔
15
        choices=USER_TYPES, required=True, widget=forms.RadioSelect
16
    )
17
    email = forms.EmailField(required=True)
1✔
18
    first_name = forms.CharField(required=True, max_length=100)
1✔
19
    last_name = forms.CharField(required=True, max_length=100)
1✔
20

21
    class Meta:
1✔
22
        model = User
1✔
23
        fields = [
1✔
24
            "user_type",
25
            "email",
26
            "first_name",
27
            "last_name",
28
            "password1",
29
            "password2",
30
        ]
31

32
    def clean(self):
1✔
33
        cleaned_data = super().clean()
×
NEW
34
        email = cleaned_data.get("email").lower()
×
NEW
35
        user_type = cleaned_data.get("user_type")
×
NEW
36
        first_name = cleaned_data.get("first_name")
×
NEW
37
        last_name = cleaned_data.get("last_name")
×
38

39
        if User.objects.filter(username=email).exists():
×
NEW
40
            raise ValidationError({"email": "A user with that email already exists."})
×
41

NEW
42
        if user_type == "tutor" and not email.endswith("@nyu.edu"):
×
NEW
43
            raise ValidationError(
×
44
                {"email": "Tutor email address must end with '@nyu.edu'."}
45
            )
46

47
        if not first_name:
×
NEW
48
            raise ValidationError({"first_name": "First name cannot be empty."})
×
49

50
        if not last_name:
×
NEW
51
            raise ValidationError({"first_name": "First name cannot be empty."})
×
52

53
        return cleaned_data
×
54

55
    def save(self, commit=True):
1✔
56
        user = super().save(commit=False)
×
NEW
57
        user.username = self.cleaned_data["email"]
×
58

59
        if commit:
×
60
            user.save()
×
NEW
61
            user.usertype.user_type = self.cleaned_data["user_type"]
×
62
            user.usertype.save()
×
63

64
        return user
×
65

66
    def isTutor(self):
1✔
NEW
67
        return super().clean().get("user_type") == "tutor"
×
68

69
    def isStudent(self):
1✔
NEW
70
        return super().clean().get("user_type") == "student"
×
71

72
    def __init__(self, *args, **kwargs):
1✔
73
        super().__init__(*args, **kwargs)
×
74
        for field in iter(self.fields):
×
NEW
75
            self.fields[field].widget.attrs.update({"class": "form-control"})
×
76

77

78
class CustomLoginForm(AuthenticationForm):
1✔
79
    def __init__(self, *args, **kwargs):
1✔
80
        super(CustomLoginForm, self).__init__(*args, **kwargs)
×
81

82
        for fieldname in ["username", "password"]:
×
NEW
83
            self.fields[fieldname].widget.attrs.update(
×
84
                {"class": "form-control", "placeholder": self.fields[fieldname].label}
85
            )
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