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

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

29 Apr 2024 04:09PM UTC coverage: 91.716% (+1.0%) from 90.674%
805

Pull #252

travis-pro

web-flow
Merge 48120f46f into a39734b39
Pull Request #252: Merge dev to prod

131 of 260 new or added lines in 14 files covered. (50.38%)

707 existing lines in 14 files now uncovered.

2015 of 2197 relevant lines covered (91.72%)

1.23 hits per line

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

96.49
/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
from django.core.validators import MinValueValidator
2✔
8
from django.core.exceptions import ValidationError
2✔
9

10

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

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

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

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

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

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

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

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

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

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

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

172

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

181
    offering_rate = forms.DecimalField(
2✔
182
        validators=[MinValueValidator(0.01)],
183
        widget=forms.NumberInput(attrs={"class": "form-control", "min": "0.01"}),
184
    )
185

186
    def __init__(self, *args, tutor_user=None, **kwargs):
2✔
UNCOV
187
        super().__init__(*args, **kwargs)
1✔
UNCOV
188
        available_subject_choices = []
1✔
UNCOV
189
        if tutor_user:
1✔
UNCOV
190
            tutor_profile = ProfileT.objects.filter(user=tutor_user).first()
1✔
UNCOV
191
            expert_subjects = Expertise.objects.filter(user=tutor_user).values_list(
1✔
192
                "subject", flat=True
193
            )
UNCOV
194
            available_subject_choices = [
1✔
195
                choice for choice in EXPERTISE_CHOICES if choice[0] in expert_subjects
196
            ]
197

UNCOV
198
            self.fields["subject"].choices = available_subject_choices
1✔
UNCOV
199
            if tutor_profile:
1✔
UNCOV
200
                if tutor_profile.preferred_mode == "both":
1✔
201
                    mode_choices = [
×
202
                        ("inperson", "In Person"),
203
                        ("remote", "Remote"),
204
                        ("both", "Both"),
205
                    ]
206
                else:
UNCOV
207
                    mode_choices = [
1✔
208
                        (
209
                            tutor_profile.preferred_mode,
210
                            tutor_profile.preferred_mode.capitalize(),
211
                        ),
212
                    ]
213

UNCOV
214
                self.fields["tutoring_mode"].choices = mode_choices
1✔
215

216
    class Meta:
2✔
217
        model = TutoringSession
2✔
218
        fields = [
2✔
219
            "tutoring_mode",
220
            "subject",
221
            "date",
222
            "offering_rate",
223
            "message",
224
            "attachment",
225
        ]
226
        tomorrow = timezone.localdate() + timedelta(days=1)
2✔
227
        next_month = timezone.localdate() + timedelta(days=90)
2✔
228
        widgets = {
2✔
229
            "date": forms.DateInput(
230
                attrs={
231
                    "type": "date",
232
                    "min": tomorrow.isoformat(),
233
                    "max": next_month.isoformat(),
234
                    "class": "form-control",
235
                    "id": "date_selector",
236
                    "onkeydown": "return false;",  #
237
                    "onpaste": "return false;",
238
                }
239
            ),
240
            "offering_rate": forms.NumberInput(attrs={"class": "form-control"}),
241
            "message": forms.Textarea(
242
                attrs={"class": "form-control", "rows": 3, "placeholder": "Message"}
243
            ),
244
            "attachment": forms.FileInput(attrs={"class": "form-control"}),
245
        }
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