Skip to content

Commit

Permalink
Merge branch 'develop' into Review&Rating
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyasan committed Mar 30, 2024
2 parents 9b05fbd + 266086f commit adf1b2e
Show file tree
Hide file tree
Showing 15 changed files with 708 additions and 68 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified .coverage
Binary file not shown.
4 changes: 2 additions & 2 deletions Dashboard/templates/Profile/studentProfile.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'TutorRegister/base.html' %}
{% comment %} {% extends 'TutorRegister/base.html' %}

{% block title %} Student Profile{% endblock %}

Expand Down Expand Up @@ -46,4 +46,4 @@ <h2 class="fw-bold mb-0 fs-2 text-center">Student Profile</h2>
<!-- Add Bootstrap and jQuery scripts if not already included -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
{% endblock %}
{% endblock %} {% endcomment %}
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 adf1b2e

Please sign in to comment.