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

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

29 Apr 2024 09:02AM UTC coverage: 91.218% (+1.7%) from 89.518%
800

push

travis-pro

web-flow
Merge pull request #250 from gcivil-nyu-org/Community-v3

add tests

8 of 39 new or added lines in 1 file covered. (20.51%)

764 existing lines in 16 files now uncovered.

1984 of 2175 relevant lines covered (91.22%)

1.23 hits per line

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

95.0
/Dashboard/forms/student_info.py
1
from django.forms import ModelForm
2✔
2
from django import forms
2✔
3
from TutorRegister.models import ProfileS
2✔
4
from django.core.exceptions import ValidationError
2✔
5
import re
2✔
6

7

8
class StudentForm(ModelForm):
2✔
9
    GENDER_CHOICES = [
2✔
10
        ("female", "Female"),
11
        ("male", "Male"),
12
        ("prefernottosay", "Prefer not to say"),
13
    ]
14

15
    GRADE_CHOICES = [
2✔
16
        ("1", "1st Grade"),
17
        ("2", "2nd Grade"),
18
        ("3", "3rd Grade"),
19
        ("4", "4th Grade"),
20
        ("5", "5th Grade"),
21
        ("6", "6th Grade"),
22
        ("7", "7th Grade"),
23
        ("8", "8th Grade"),
24
        ("9", "9th Grade"),
25
        ("10", "10th Grade"),
26
        ("11", "11th Grade"),
27
        ("12", "12th Grade"),
28
        ("undergrad", "Undergraduate"),
29
        ("grad", "Graduate"),
30
        ("postgrad", "Post-graduate"),
31
    ]
32

33
    MODE_CHOICES = [
2✔
34
        ("inperson", "In-person"),
35
        ("remote", "Remote"),
36
        ("both", "Both"),
37
    ]
38

39
    gender = forms.ChoiceField(
2✔
40
        choices=GENDER_CHOICES,
41
        widget=forms.Select(
42
            attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
43
        ),
44
    )
45
    zip = forms.CharField(required=True, max_length=5)
2✔
46
    grade = forms.ChoiceField(
2✔
47
        choices=GRADE_CHOICES,
48
        widget=forms.Select(
49
            attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
50
        ),
51
    )
52
    preferred_mode = forms.ChoiceField(
2✔
53
        choices=MODE_CHOICES,
54
        widget=forms.Select(
55
            attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
56
        ),
57
    )
58

59
    class Meta:
2✔
60
        model = ProfileS
2✔
61
        fields = [
2✔
62
            "fname",
63
            "lname",
64
            "gender",
65
            "zip",
66
            "school",
67
            "grade",
68
            "preferred_mode",
69
            "intro",
70
        ]
71
        labels = {
2✔
72
            "fname": "First Name",
73
            "lname": "Last Name",
74
            "gender": "Gender",
75
            "zip": "Zip Code",
76
            "school": "School",
77
            "grade": "Grade Level",
78
            "preferred_mode": "Preferred Tutoring Mode",
79
            "intro": "Introduction",
80
        }
81

82
        widgets = {
2✔
83
            "fname": forms.TextInput(
84
                attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
85
            ),
86
            "lname": forms.TextInput(
87
                attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
88
            ),
89
            "school": forms.TextInput(
90
                attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
91
            ),
92
            "intro": forms.Textarea(
93
                attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
94
            ),
95
        }
96

97
    def clean(self):
2✔
UNCOV
98
        cleaned_data = super().clean()
1✔
UNCOV
99
        zip = cleaned_data.get("zip")
1✔
100

UNCOV
101
        if bool(re.match(r"^\d{5}$", zip)) is False:
1✔
102
            raise ValidationError({"zip": "The zip code must be a 5-digit number."})
×
103

UNCOV
104
        return cleaned_data
1✔
105

106
    def save(self, commit=True):
2✔
UNCOV
107
        user = super().save(commit=False)
1✔
UNCOV
108
        user.zip = self.cleaned_data["zip"]
1✔
109

UNCOV
110
        if commit:
1✔
111
            user.save()
×
112

UNCOV
113
        return user
1✔
114

115
    def __init__(self, *args, **kwargs):
2✔
UNCOV
116
        super().__init__(*args, **kwargs)
1✔
UNCOV
117
        for field in iter(self.fields):
1✔
UNCOV
118
            self.fields[field].widget.attrs.update({"class": "form-control"})
1✔
119

120

121
class StudentImageForm(forms.ModelForm):
2✔
122
    class Meta:
2✔
123
        model = ProfileS
2✔
124
        fields = ["image"]
2✔
125
        labels = {
2✔
126
            "image": "Profile Image",
127
        }
128
        widgets = {
2✔
129
            "image": forms.FileInput(
130
                attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
131
            ),
132
        }
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

© 2025 Coveralls, Inc