Skip to content

Commit 93c7bf7

Browse files
Merge pull request #174 from UNLV-CS472-672/quick-fixes
Quick fixes
2 parents 7dd01a6 + 39d8fd2 commit 93c7bf7

File tree

8 files changed

+120
-25
lines changed

8 files changed

+120
-25
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 5.1.6 on 2025-04-23 20:47
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('search', '0002_alter_subject_table'),
10+
('users', '0010_profile_date_of_birth_profile_phone_number_and_more'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='studentprofile',
16+
name='emergency_contact_name',
17+
field=models.CharField(default='Unknown', max_length=100),
18+
),
19+
migrations.AlterField(
20+
model_name='studentprofile',
21+
name='emergency_contact_phone_number',
22+
field=models.CharField(default='1234567890', max_length=15),
23+
),
24+
migrations.AlterField(
25+
model_name='studentprofile',
26+
name='preferred_subjects',
27+
field=models.ManyToManyField(blank=True, to='search.subject'),
28+
),
29+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.1.6 on 2025-04-23 20:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('users', '0011_alter_studentprofile_emergency_contact_name_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='tutorprofile',
15+
name='hourly_rate',
16+
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=6),
17+
),
18+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 5.1.6 on 2025-04-23 21:28
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('users', '0012_alter_tutorprofile_hourly_rate'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='studentprofile',
16+
name='parent_profile',
17+
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.parentprofile'),
18+
),
19+
]

backend/apps/users/models.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class TutorProfile(models.Model):
5050
state = models.CharField(max_length=2, default="NA")
5151

5252
bio = models.TextField(blank=True)
53-
hourly_rate = models.DecimalField(max_digits=6, decimal_places=2)
53+
hourly_rate = models.DecimalField(max_digits=6, decimal_places=2, default= 0.00)
5454

5555
subjects = models.ManyToManyField(to="search.Subject")
5656
rating = models.DecimalField(max_digits=2, decimal_places=1, default=1.0)
@@ -99,12 +99,21 @@ def __str__(self):
9999
class StudentProfile(models.Model):
100100
profile = models.OneToOneField(Profile, on_delete=models.CASCADE)
101101
# also including a reference to the parent profile
102-
parent_profile = models.OneToOneField(ParentProfile, on_delete=models.CASCADE)
102+
parent_profile = models.ForeignKey(ParentProfile, on_delete=models.CASCADE)
103103
# https://stackoverflow.com/questions/849142/how-to-limit-the-maximum-value-of-a-numeric-field-in-a-django-model
104104
grade_level = models.IntegerField(default=1, validators=[MaxValueValidator(12),MinValueValidator(1)])
105-
preferred_subjects = models.ManyToManyField(to="search.Subject")
106-
emergency_contact_name = models.CharField(max_length=100)
107-
emergency_contact_phone_number = models.CharField(max_length=15)
105+
preferred_subjects = models.ManyToManyField(
106+
to="search.Subject",
107+
blank=True
108+
)
109+
emergency_contact_name = models.CharField(
110+
max_length=100,
111+
default = "Unknown"
112+
)
113+
emergency_contact_phone_number = models.CharField(
114+
max_length=15,
115+
default = "1234567890"
116+
)
108117

109118
def clean(self):
110119
if self.profile.role != self.profile.STUDENT:

backend/apps/users/tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_register_student_profile(self):
1414
url = "/users/register/" # make sure you have this in urls.py
1515
data = {
1616
"country": "US",
17-
"displayName": "studentuser",
17+
"username": "studentuser",
1818
"email": "student@example.com",
1919
"firstName": "Student",
2020
"lastName": "User",
@@ -36,7 +36,7 @@ def test_register_tutor_profile(self):
3636
url = "/users/register/"
3737
data = {
3838
"country": "US",
39-
"displayName": "tutoruser",
39+
"username": "tutoruser",
4040
"email": "tutor@example.com",
4141
"firstName": "Tutor",
4242
"lastName": "User",
@@ -56,7 +56,7 @@ def test_register_parent_profile(self):
5656
url = "/users/register/"
5757
data = {
5858
"country": "US",
59-
"displayName": "parentuser2",
59+
"username": "parentuser2",
6060
"email": "parent2@example.com",
6161
"firstName": "Parent",
6262
"lastName": "User",

backend/apps/users/views.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from apps.users.models import Profile, TutorProfile, ParentProfile, StudentProfile
99
from apps.uploads.models import UploadRecord, ProfilePicture
1010
from rest_framework import status
11+
from apps.search.models import Subject
1112
from rest_framework.response import Response
1213
from rest_framework.permissions import AllowAny, IsAuthenticated
1314
from rest_framework_simplejwt.tokens import RefreshToken
@@ -63,13 +64,15 @@ def logout_view(request):
6364
@permission_classes([AllowAny])
6465
def register_profile(request):
6566
country = request.data["country"]
66-
username = request.data["displayName"]
67+
username = request.data["username"]
6768
email = request.data["email"]
6869
first_name = request.data["firstName"]
6970
last_name = request.data["lastName"]
7071
password = request.data["password"]
71-
role = request.data["role"] # Get the selected role
72-
# role = Profile.STUDENT
72+
role = request.data.get("role") # Get the selected role
73+
if not role:
74+
role = Profile.TUTOR
75+
7376
# Create user
7477
user = User.objects.create_user(
7578
username=username,
@@ -80,8 +83,6 @@ def register_profile(request):
8083
)
8184
# Create associated Profile
8285
profile = Profile.objects.create(user, role)
83-
84-
8586
image=request.data.get("image") #For now, get an optional image
8687

8788
# Store optional profile picture
@@ -96,31 +97,48 @@ def register_profile(request):
9697

9798
# Create Tutor Profile if role is Tutor
9899
if int(profile.role) == Profile.TUTOR:
99-
city=request.data["city"]
100-
state=request.data["state"]
101-
bio=request.data["bio"]
102-
hourly_rate=request.data["hourly_rate"]
100+
city=request.data.get("city") or "Unknown"
101+
state=request.data.get("state") or "NA"
102+
bio=request.data.get("bio")
103+
if not bio:
104+
bio = ""
105+
hourly_rate=request.data.get("hourly_rate") or 0.00
103106
tutor = TutorProfile.objects.create(profile=profile, city=city, state=state, bio=bio, hourly_rate=hourly_rate)
104107
# otherwise, check if parent
105108
elif int(profile.role) == Profile.PARENT:
106109
parent = ParentProfile.objects.create(profile=profile)
107110
# otherwise, student
108111
else:
109-
parent_profile = request.data["parent_profile"]
110-
grade_level = request.data["grade_level"]
111-
preferred_subjects = request.data["preferred_subjects"]
112-
emergency_contact_name = request.data["emergency_contact_name"]
113-
emergency_contact_phone_number = request.data["emergency_contact_phone_number"]
114-
parent_profile_id = request.data["parent_profile"]
115-
parent_profile_instance = ParentProfile.objects.get(id=parent_profile_id)
112+
parent_profile = request.data.get("parent_profile")
113+
grade_level = request.data.get("grade_level")
114+
preferred_subjects = request.data.get("preferred_subjects")
115+
grade_level = request.data.get("grade_level")
116+
if not grade_level:
117+
grade_level = 1 # same as the model default
118+
119+
emergency_contact_name = request.data.get("emergency_contact_name") or "Unknown"
120+
emergency_contact_phone_number = request.data.get("emergency_contact_phone_number") or "1234567890"
121+
parent_profile_id = request.data.get("parent_profile")
122+
if parent_profile_id:
123+
parent_profile_instance = ParentProfile.objects.get(id=parent_profile_id)
124+
125+
else:
126+
parent_profile_instance = ParentProfile.objects.get(id=1) # for now
127+
116128
student = StudentProfile.objects.create(
117129
profile=profile,
118130
parent_profile=parent_profile_instance,
119131
grade_level = grade_level,
120132
emergency_contact_name = emergency_contact_name,
121133
emergency_contact_phone_number = emergency_contact_phone_number
122134
)
123-
student.preferred_subjects.set(preferred_subjects)
135+
# For now, just to get sign up to work without full frontend + backend connection
136+
if not preferred_subjects:
137+
default_subjects = Subject.objects.filter(title__in=["Biology"])
138+
student.preferred_subjects.set(default_subjects)
139+
else:
140+
student.preferred_subjects.set(preferred_subjects)
141+
124142
return Response({"message": "User registered successfully"}, status=status.HTTP_201_CREATED)
125143

126144
@api_view(['POST'])

backend/backend/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
'django.contrib.contenttypes',
6060
'django.contrib.sessions',
6161
'django.contrib.messages',
62+
'django_extensions',
6263
"daphne", #daphne has to be before django.contrib.staticfiles
6364
'django.contrib.staticfiles',
6465
"apps.api", # our api app

backend/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pytest-django==4.8.0
2323
pytest-asyncio==0.23.5
2424
factory-boy==3.3.0
2525
coverage==7.5.0
26+
django-extensions==4.1
2627

2728
# Dev dependencies
2829
pytest-cov==6.1.1

0 commit comments

Comments
 (0)