Skip to content

Commit

Permalink
Merge pull request #42 from gcivil-nyu-org/feature/shihui
Browse files Browse the repository at this point in the history
Create Student & Tutor Profile
  • Loading branch information
Shihuihuang1103 committed Mar 4, 2024
2 parents 851c6bc + 4cf4176 commit 7733fd7
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 393 deletions.
98 changes: 82 additions & 16 deletions TutorRegister/StudentForm.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,95 @@
from django.forms import ModelForm
from django import forms
from django.core.validators import RegexValidator
from TutorRegister.models import ProfileS


class StudentForm(forms.Form):
class StudentForm(ModelForm):
GENDER_CHOICES = [
("male", "Male"),
("female", "Female"),
("male", "Male"),
("prefernottosay", "Prefer not to say"),
]

GRADE_CHOICES = [
("1", "1st Grade"),
("2", "2nd Grade"),
("3", "3rd Grade"),
("4", "4th Grade"),
("5", "5th Grade"),
("6", "6th Grade"),
("7", "7th Grade"),
("8", "8th Grade"),
("9", "9th Grade"),
("10", "10th Grade"),
("11", "11th Grade"),
("12", "12th Grade"),
("undergrad", "Undergraduate"),
("grad", "Graduate"),
("postgrad", "Post-graduate"),
]

PREFERRED_MODE_CHOICES = [
("online", "Online"),
("in_person", "In-person"),
MODE_CHOICES = [
("inperson", "In-person"),
("remote", "Remote"),
("both", "Both"),
]

gender = forms.ChoiceField(choices=GENDER_CHOICES, label="Gender")
zip_code = forms.CharField(
max_length=10,
label="Zip Code",
validators=[RegexValidator(r"^\d{5}$", message="Enter a valid ZIP code.")],
gender = forms.ChoiceField(
choices=GENDER_CHOICES,
widget=forms.Select(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
)
grade = forms.ChoiceField(
choices=GRADE_CHOICES,
widget=forms.Select(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
)
school = forms.CharField(max_length=100, label="school")
preferred_mode = forms.ChoiceField(
choices=PREFERRED_MODE_CHOICES, label="Preferred Mode"
choices=MODE_CHOICES,
widget=forms.Select(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
)
introduction = forms.CharField(widget=forms.Textarea, label="Introduction")

def clean(self):
return super().clean()
class Meta:
model = ProfileS
fields = [
"fname",
"lname",
"gender",
"zip",
"school",
"grade",
"preferred_mode",
"intro",
]
labels = {
"fname": "First Name",
"lname": "Last Name",
"gender": "Gender",
"zip": "Zip Code",
"school": "School",
"grade": "Grade Level",
"preferred_mode": "Preferred Tutoring Mode",
"intro": "Introduction",
}

widgets = {
"fname": forms.TextInput(
attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
),
"lname": forms.TextInput(
attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
),
"zip": forms.TextInput(
attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
),
"school": forms.TextInput(
attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
),
"intro": forms.Textarea(
attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
),
}
204 changes: 173 additions & 31 deletions TutorRegister/TutorForm.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,188 @@
from django import forms
from django.core.validators import RegexValidator, MinValueValidator

# from django.core.validators import RegexValidator, MinValueValidator
from django.forms import ModelForm
from TutorRegister.models import ProfileT, Availability

class TutorForm(forms.Form):

class TutorForm(ModelForm):
GENDER_CHOICES = [
("male", "Male"),
("female", "Female"),
("male", "Male"),
("prefernottosay", "Prefer not to say"),
]

MODE_CHOICES = [
("inperson", "In-person"),
("remote", "Remote"),
("both", "Both"),
]

GRADE_CHOICE = [
("freshman", "Freshman"),
("sophomore", "Sophomore"),
("junior", "Junior"),
("senior", "Senior"),
("grad", "Graduate Student"),
("phd", "PhD Student"),
]

PREFERRED_MODE_CHOICES = [
("online", "Online"),
("in_person", "In-person"),
EXPERTISE_CHOICES = [
("math", "Mathematics"),
("algebra", "Algebra"),
("calculus", "Calculus"),
("computer_sci", "Computer Science"),
("elementary_math", "Elementary Math"),
("geometry", "Geometry"),
("high_school_math", "High School Math"),
("regents_math", "Regents Math"),
("act", "ACT"),
("gmat", "GMAT"),
("gre", "GRE"),
("ielts", "IELTS"),
("lsat", "LSAT"),
("sat", "SAT"),
("toefl", "TOEFL"),
("esl", "ESL"),
("economics", "Economics"),
("elementry_reading", "Elementary Reading"),
("history", "History"),
("english", "English"),
("social_studies", "Social Studies"),
("writing", "Writing"),
("biology", "Biology"),
("physics", "Physics"),
("arabic", "Arabic"),
("chinese", "Chinese"),
("french", "French"),
("italian", "Italian"),
("german", "German"),
("russian", "Russian"),
("spanish", "Spanish"),
("cello", "Cello"),
("piano", "Piano"),
("singing", "Singing"),
("violin", "Violin"),
]

gender = forms.ChoiceField(choices=GENDER_CHOICES, label="Gender")
zip_code = forms.CharField(
max_length=10,
label="Zip Code",
validators=[RegexValidator(r"^\d{5}$", message="Enter a valid ZIP code.")],
gender = forms.ChoiceField(
choices=GENDER_CHOICES,
widget=forms.Select(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
)
major = forms.CharField(max_length=100, label="Major")
preferred_mode = forms.ChoiceField(
choices=PREFERRED_MODE_CHOICES, label="Preferred Mode"
choices=MODE_CHOICES,
widget=forms.Select(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
)
grade = forms.ChoiceField(
choices=GRADE_CHOICE,
widget=forms.Select(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
)
introduction = forms.CharField(widget=forms.Textarea, label="Introduction")
min_salary = forms.IntegerField(
validators=[MinValueValidator(0)], label="Minimum Salary ($)"

expertise = forms.MultipleChoiceField(
choices=EXPERTISE_CHOICES,
widget=forms.SelectMultiple(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
required=False,
)
max_salary = forms.IntegerField(
validators=[MinValueValidator(0)], label="Maximum Salary ($)"

class Meta:
model = ProfileT
fields = [
"fname",
"lname",
"gender",
"zip",
"grade",
"major",
"preferred_mode",
"salary_min",
"salary_max",
"intro",
]
labels = {
"fname": "First Name",
"lname": "Last Name",
"gender": "Gender",
"zip": "Zip Code",
"grade": "Grade",
"major": "Major",
"preferred_mode": "Preferred Tutoring Mode",
"intro": "Introduction",
"salary_min": "Minimum Hourly Rate",
"salary_max": "Maximum Hourly Rate",
}

widgets = {
"fname": forms.TextInput(
attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
),
"lname": forms.TextInput(
attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
),
"zip": forms.TextInput(
attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
),
"major": forms.TextInput(
attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
),
"salary_min": forms.TextInput(
attrs={"class": "form-control", "style": "margin-bottom: 10px; col: sm"}
),
"salary_max": forms.TextInput(
attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
),
"intro": forms.Textarea(
attrs={"class": "form-control", "style": "margin-bottom: 10px;"}
),
}


class AvailabilityForm(forms.ModelForm):
DAY_CHOICES = [
("monday", "Monday"),
("tuesday", "Tuesday"),
("wednesday", "Wednesday"),
("thursday", "Thursday"),
("friday", "Friday"),
("saturday", "Saturday"),
("sunday", "Sunday"),
]

day_of_week = forms.ChoiceField(
choices=DAY_CHOICES,
widget=forms.Select(
attrs={"class": "form-select", "style": "margin-bottom: 10px;"}
),
)

def clean(self):
cleaned_data = super().clean()
min_salary = cleaned_data.get("min_salary")
max_salary = cleaned_data.get("max_salary")

if (
min_salary is not None
and max_salary is not None
and min_salary > max_salary
):
raise forms.ValidationError(
"Minimum salary must be less than or equal to maximum salary"
)
class Meta:
model = Availability
fields = [
"day_of_week",
"start_time",
"end_time",
]

widgets = {
"start_time": forms.TimeInput(
attrs={
"class": "form-control",
"type": "time",
"style": "margin-bottom: 10px;",
}
),
"end_time": forms.TimeInput(
attrs={
"class": "form-control",
"type": "time",
"style": "margin-bottom: 10px;",
}
),
}

0 comments on commit 7733fd7

Please sign in to comment.