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

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

01 Apr 2024 04:47PM UTC coverage: 90.169% (+0.1%) from 90.028%
508

push

travis-pro

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

Merge Develop to Master

367 of 421 new or added lines in 25 files covered. (87.17%)

2 existing lines in 2 files now uncovered.

1284 of 1424 relevant lines covered (90.17%)

2.71 hits per line

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

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

7

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

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

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

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

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

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

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

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

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

154
    def get_user_category_choices(self, user):
3✔
155
        if not user:
3✔
NEW
156
            return []
×
157

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

169

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

178
    def __init__(self, *args, tutor_user=None, **kwargs):
3✔
179
        super().__init__(*args, **kwargs)
3✔
180

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

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

207
                self.fields["tutoring_mode"].choices = mode_choices
3✔
208

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