Skip to content

Commit

Permalink
Merge pull request #145 from gcivil-nyu-org/Ziyi
Browse files Browse the repository at this point in the history
Tutor Filter Updated
  • Loading branch information
zw3917 committed Mar 30, 2024
2 parents 0c5ff85 + 04afbc2 commit 266086f
Show file tree
Hide file tree
Showing 11 changed files with 674 additions and 38 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified .coverage
Binary file not shown.
67 changes: 66 additions & 1 deletion TutorFilter/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from django.forms import ModelForm
from TutorRegister.models import ProfileT, Expertise, TutoringSession
from TutorRegister.models import ProfileT, Expertise, TutoringSession, Favorite
from Dashboard.choices import EXPERTISE_CHOICES
from django.utils import timezone

Expand Down Expand Up @@ -64,6 +64,35 @@ class TutorFilterForm(forms.Form):
("violin", "Violin"),
]

RATE_CHOICE = [
("..", ".."),
(">= 1 star", ">= 1 star"),
(">= 2 stars", ">= 2 stars"),
(">= 3 stars", ">= 3 stars"),
(">= 4 stars", ">= 4 stars"),
("= 5 stars", "= 5 stars"),
]

SORT_CHOICE = [
("..", ".."),
("Highest Rating", "Highest Rating"),
("Highest Price", "Highest Price"),
("Lowest Price", "Lowest Price"),
]

def __init__(self, *args, **kwargs):
user = kwargs.pop("user", None)
super(TutorFilterForm, self).__init__(*args, **kwargs)
# Set the choices for the 'category' field
self.fields["category"] = forms.ChoiceField(
choices=self.get_user_category_choices(user),
required=False,
widget=forms.Select(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
label="Select a category..",
)

preferred_mode = forms.ChoiceField(
choices=MODE_CHOICES,
widget=forms.Select(
Expand Down Expand Up @@ -100,6 +129,42 @@ class TutorFilterForm(forms.Form):
),
required=False,
)
rating = forms.ChoiceField(
choices=RATE_CHOICE,
widget=forms.Select(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
required=False,
)
saved = forms.ChoiceField(
choices=SORT_CHOICE,
widget=forms.Select(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
required=False,
)
sortBy = forms.ChoiceField(
choices=SORT_CHOICE,
widget=forms.Select(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
required=False,
)

def get_user_category_choices(self, user):
if not user:
return []

# Here we filter the Favorite objects by the current user (student)
# and create a tuple for the form's choices field
res = []
res = res + [
(fav.category, fav.category)
for fav in Favorite.objects.filter(student=user).distinct()
]
res = list(set(res))
res.insert(0, ("..", ".."))
return res


class TutoringSessionRequestForm(forms.ModelForm):
Expand Down

0 comments on commit 266086f

Please sign in to comment.