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

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

15 Apr 2024 04:27PM UTC coverage: 90.674%. Remained the same
719

push

travis-pro

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

exempt contact from middleware

1 of 1 new or added line in 1 file covered. (100.0%)

713 existing lines in 14 files now uncovered.

1789 of 1973 relevant lines covered (90.67%)

1.23 hits per line

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

96.23
/TutorFilter/forms.py
1
from django import forms
2✔
2
from django.forms import ModelForm
2✔
3
from TutorRegister.models import ProfileT, Expertise, TutoringSession, Favorite
2✔
4
from Dashboard.choices import EXPERTISE_CHOICES
2✔
5
from django.utils import timezone
2✔
6
from datetime import timedelta
2✔
7

8

9
class TutorFilterForm(forms.Form):
2✔
10
    # username = forms.CharField(required=False)
11
    # email = forms.EmailField(required=False)
12
    MODE_CHOICES = [
2✔
13
        ("..", ".."),
14
        ("inperson", "In-person"),
15
        ("remote", "Remote"),
16
        ("both", "Both"),
17
    ]
18

19
    GRADE_CHOICE = [
2✔
20
        ("..", ".."),
21
        ("freshman", "Freshman"),
22
        ("sophomore", "Sophomore"),
23
        ("junior", "Junior"),
24
        ("senior", "Senior"),
25
        ("grad", "Graduate Student"),
26
        ("phd", "PhD Student"),
27
    ]
28

29
    EXPERTISE_CHOICES = [
2✔
30
        ("..", ".."),
31
        ("math", "Mathematics"),
32
        ("algebra", "Algebra"),
33
        ("calculus", "Calculus"),
34
        ("computer_sci", "Computer Science"),
35
        ("elementary_math", "Elementary Math"),
36
        ("geometry", "Geometry"),
37
        ("high_school_math", "High School Math"),
38
        ("regents_math", "Regents Math"),
39
        ("act", "ACT"),
40
        ("gmat", "GMAT"),
41
        ("gre", "GRE"),
42
        ("ielts", "IELTS"),
43
        ("lsat", "LSAT"),
44
        ("sat", "SAT"),
45
        ("toefl", "TOEFL"),
46
        ("esl", "ESL"),
47
        ("economics", "Economics"),
48
        ("elementry_reading", "Elementary Reading"),
49
        ("history", "History"),
50
        ("english", "English"),
51
        ("social_studies", "Social Studies"),
52
        ("writing", "Writing"),
53
        ("biology", "Biology"),
54
        ("physics", "Physics"),
55
        ("arabic", "Arabic"),
56
        ("chinese", "Chinese"),
57
        ("french", "French"),
58
        ("italian", "Italian"),
59
        ("german", "German"),
60
        ("russian", "Russian"),
61
        ("spanish", "Spanish"),
62
        ("cello", "Cello"),
63
        ("piano", "Piano"),
64
        ("singing", "Singing"),
65
        ("violin", "Violin"),
66
    ]
67

68
    RATE_CHOICE = [
2✔
69
        ("..", ".."),
70
        (">= 1 star", ">= 1 star"),
71
        (">= 2 stars", ">= 2 stars"),
72
        (">= 3 stars", ">= 3 stars"),
73
        (">= 4 stars", ">= 4 stars"),
74
        ("= 5 stars", "= 5 stars"),
75
    ]
76

77
    SORT_CHOICE = [
2✔
78
        ("..", ".."),
79
        ("Highest Rating", "Highest Rating"),
80
        ("Highest Price", "Highest Price"),
81
        ("Lowest Price", "Lowest Price"),
82
    ]
83

84
    def __init__(self, *args, **kwargs):
2✔
UNCOV
85
        user = kwargs.pop("user", None)
1✔
UNCOV
86
        super(TutorFilterForm, self).__init__(*args, **kwargs)
1✔
87
        # Set the choices for the 'category' field
UNCOV
88
        self.fields["category"] = forms.ChoiceField(
1✔
89
            choices=self.get_user_category_choices(user),
90
            required=False,
91
            widget=forms.Select(
92
                attrs={"class": "form-select border-2", "style": "margin-bottom: 10px;"}
93
            ),
94
            label="Select a category..",
95
        )
96

97
    preferred_mode = forms.ChoiceField(
2✔
98
        choices=MODE_CHOICES,
99
        widget=forms.Select(
100
            attrs={"class": "form-select border-2", "style": "margin-bottom: 10px;"}
101
        ),
102
        required=False,
103
    )
104
    grade = forms.ChoiceField(
2✔
105
        choices=GRADE_CHOICE,
106
        widget=forms.Select(
107
            attrs={"class": "form-select border-2", "style": "margin-bottom: 10px;"}
108
        ),
109
        required=False,
110
    )
111

112
    expertise = forms.ChoiceField(
2✔
113
        choices=EXPERTISE_CHOICES,
114
        widget=forms.Select(
115
            attrs={"class": "form-select border-2", "style": "margin-bottom: 10px;"}
116
        ),
117
        required=False,
118
    )
119

120
    zipcode = forms.CharField(
2✔
121
        max_length=255,
122
        widget=forms.TextInput(
123
            attrs={"class": "form-control border-2", "style": "margin-bottom: 10px;"}
124
        ),
125
        required=False,
126
    )
127
    salary_max = forms.IntegerField(
2✔
128
        widget=forms.NumberInput(
129
            attrs={"class": "form-control border-2", "style": "margin-bottom: 10px;"}
130
        ),
131
        required=False,
132
    )
133
    rating = forms.ChoiceField(
2✔
134
        choices=RATE_CHOICE,
135
        widget=forms.Select(
136
            attrs={"class": "form-select border-2", "style": "margin-bottom: 10px;"}
137
        ),
138
        required=False,
139
    )
140
    saved = forms.ChoiceField(
2✔
141
        choices=SORT_CHOICE,
142
        widget=forms.Select(
143
            attrs={"class": "form-select border-2", "style": "margin-bottom: 10px;"}
144
        ),
145
        required=False,
146
    )
147
    sortBy = forms.ChoiceField(
2✔
148
        choices=SORT_CHOICE,
149
        widget=forms.Select(
150
            attrs={"class": "form-select border-2", "style": "margin-bottom: 10px;"}
151
        ),
152
        required=False,
153
    )
154

155
    def get_user_category_choices(self, user):
2✔
UNCOV
156
        if not user:
1✔
157
            return []
×
158

159
        # Here we filter the Favorite objects by the current user (student)
160
        # and create a tuple for the form's choices field
UNCOV
161
        res = []
1✔
UNCOV
162
        res = res + [
1✔
163
            (fav.category, fav.category)
164
            for fav in Favorite.objects.filter(student=user).distinct()
165
        ]
UNCOV
166
        res = list(set(res))
1✔
UNCOV
167
        res.insert(0, ("..", ".."))
1✔
UNCOV
168
        return res
1✔
169

170

171
class TutoringSessionRequestForm(forms.ModelForm):
2✔
172
    subject = forms.ChoiceField(
2✔
173
        choices=[], widget=forms.Select(attrs={"class": "form-select"})
174
    )
175
    tutoring_mode = forms.ChoiceField(
2✔
176
        choices=[], widget=forms.Select(attrs={"class": "form-select"})
177
    )
178

179
    def __init__(self, *args, tutor_user=None, **kwargs):
2✔
UNCOV
180
        super().__init__(*args, **kwargs)
1✔
181

UNCOV
182
        available_subject_choices = []
1✔
UNCOV
183
        if tutor_user:
1✔
UNCOV
184
            tutor_profile = ProfileT.objects.filter(user=tutor_user).first()
1✔
UNCOV
185
            expert_subjects = Expertise.objects.filter(user=tutor_user).values_list(
1✔
186
                "subject", flat=True
187
            )
UNCOV
188
            available_subject_choices = [
1✔
189
                choice for choice in EXPERTISE_CHOICES if choice[0] in expert_subjects
190
            ]
191

UNCOV
192
            self.fields["subject"].choices = available_subject_choices
1✔
UNCOV
193
            if tutor_profile:
1✔
UNCOV
194
                if tutor_profile.preferred_mode == "both":
1✔
195
                    mode_choices = [
×
196
                        ("inperson", "In Person"),
197
                        ("remote", "Remote"),
198
                        ("both", "Both"),
199
                    ]
200
                else:
UNCOV
201
                    mode_choices = [
1✔
202
                        (
203
                            tutor_profile.preferred_mode,
204
                            tutor_profile.preferred_mode.capitalize(),
205
                        ),
206
                    ]
207

UNCOV
208
                self.fields["tutoring_mode"].choices = mode_choices
1✔
209

210
    class Meta:
2✔
211
        model = TutoringSession
2✔
212
        fields = [
2✔
213
            "tutoring_mode",
214
            "subject",
215
            "date",
216
            "offering_rate",
217
            "message",
218
            "attachment",
219
        ]
220
        tomorrow = timezone.localdate() + timedelta(days=1)
2✔
221
        widgets = {
2✔
222
            "date": forms.DateInput(
223
                attrs={
224
                    "type": "date",
225
                    "min": tomorrow.isoformat(),
226
                    "class": "form-control",
227
                    "id": "date_selector",
228
                }
229
            ),
230
            "offering_rate": forms.NumberInput(attrs={"class": "form-control"}),
231
            "message": forms.Textarea(
232
                attrs={"class": "form-control", "rows": 3, "placeholder": "Message"}
233
            ),
234
            "attachment": forms.FileInput(attrs={"class": "form-control"}),
235
        }
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