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

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

21 Apr 2024 04:47AM UTC coverage: 90.368% (-0.3%) from 90.674%
759

push

travis-pro

samkitshah18
Resolved Issues: 211, 203, 210

9 of 10 new or added lines in 1 file covered. (90.0%)

5 existing lines in 1 file now uncovered.

1792 of 1983 relevant lines covered (90.37%)

0.9 hits per line

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

95.24
/TutorFilter/forms.py
1
from django import forms
1✔
2
from django.forms import ModelForm
1✔
3
from TutorRegister.models import ProfileT, Expertise, TutoringSession, Favorite
1✔
4
from Dashboard.choices import EXPERTISE_CHOICES
1✔
5
from django.utils import timezone
1✔
6
from datetime import timedelta
1✔
7
from django.core.validators import MinValueValidator
1✔
8
from django.core.exceptions import ValidationError
1✔
9

10

11

12

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

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

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

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

81
    SORT_CHOICE = [
1✔
82
        ("..", ".."),
83
        ("Highest Rating", "Highest Rating"),
84
        ("Highest Price", "Highest Price"),
85
        ("Lowest Price", "Lowest Price"),
86
    ]
87

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

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

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

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

159
    def get_user_category_choices(self, user):
1✔
160
        if not user:
1✔
161
            return []
×
162

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

174

175
class TutoringSessionRequestForm(forms.ModelForm):
1✔
176
    subject = forms.ChoiceField(
1✔
177
        choices=[], widget=forms.Select(attrs={"class": "form-select"})
178
    )
179
    tutoring_mode = forms.ChoiceField(
1✔
180
        choices=[], widget=forms.Select(attrs={"class": "form-select"})
181
    )
182
    
183
    offering_rate = forms.DecimalField(
1✔
184
        validators=[MinValueValidator(0.01)], 
185
        widget=forms.NumberInput(attrs={"class": "form-control", "min": "0.01"})
186
    )
187

188
    date = forms.DateField(widget=forms.DateInput(attrs={
1✔
189
        "type": "date",
190
        "class": "form-control",
191
        "id": "date_selector"
192
    }))
193
    
194
    def __init__(self, *args, tutor_user=None, **kwargs):
1✔
195
        super().__init__(*args, **kwargs)
1✔
196
        self.fields['date'].widget.attrs['min'] = (timezone.localdate() + timedelta(days=1)).isoformat()
1✔
197
        available_subject_choices = []
1✔
198
        if tutor_user:
1✔
199
            tutor_profile = ProfileT.objects.filter(user=tutor_user).first()
1✔
200
            expert_subjects = Expertise.objects.filter(user=tutor_user).values_list(
1✔
201
                "subject", flat=True
202
            )
203
            available_subject_choices = [
1✔
204
                choice for choice in EXPERTISE_CHOICES if choice[0] in expert_subjects
205
            ]
206

207
            self.fields["subject"].choices = available_subject_choices
1✔
208
            if tutor_profile:
1✔
209
                if tutor_profile.preferred_mode == "both":
1✔
210
                    mode_choices = [
×
211
                        ("inperson", "In Person"),
212
                        ("remote", "Remote"),
213
                        ("both", "Both"),
214
                    ]
215
                else:
216
                    mode_choices = [
1✔
217
                        (
218
                            tutor_profile.preferred_mode,
219
                            tutor_profile.preferred_mode.capitalize(),
220
                        ),
221
                    ]
222

223
                self.fields["tutoring_mode"].choices = mode_choices
1✔
224
                
225
    def clean_date(self):
1✔
226
        date = self.cleaned_data['date']
1✔
227
        if date < timezone.localdate() + timedelta(days=1):
1✔
228
            raise ValidationError("Date cannot be in the past.")
1✔
NEW
229
        return date
×
230

231
    class Meta:
1✔
232
        model = TutoringSession
1✔
233
        fields = [
1✔
234
            "tutoring_mode",
235
            "subject",
236
            "date",
237
            "offering_rate",
238
            "message",
239
            "attachment",
240
        ]
241
        tomorrow = timezone.localdate() + timedelta(days=1)
1✔
242
        widgets = {
1✔
243
            # "date": forms.DateInput(
244
            #     attrs={
245
            #         "type": "date",
246
            #         "min": tomorrow.isoformat(),
247
            #         "class": "form-control",
248
            #         "id": "date_selector",
249
            #     }
250
            # ),
251
            # "offering_rate": forms.NumberInput(attrs={"class": "form-control"}),
252
            "message": forms.Textarea(
253
                attrs={"class": "form-control", "rows": 3, "placeholder": "Message"}
254
            ),
255
            "attachment": forms.FileInput(attrs={"class": "form-control"}),
256
        }
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