Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 158 teacher teach edit student details #185

Merged
merged 56 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
a5a9c62
revert
Sep 28, 2023
ac2b2ac
adapted the pdf view to react
Sep 28, 2023
0a8c260
adapted the pdf view to react
Sep 28, 2023
46a65ed
resolving conflicts
Sep 28, 2023
a999996
removing reverse
Oct 2, 2023
e8729b7
resolving conflicts
Oct 2, 2023
f0209d6
merge
Oct 2, 2023
d1d0615
added the pdf download button
Oct 2, 2023
78e9f28
added csv download
Oct 2, 2023
26d4c27
fixing message
Oct 4, 2023
4092155
added redirect
Oct 4, 2023
3042697
cleaning up
Oct 4, 2023
4378cda
cleaning up
Oct 4, 2023
c6ee4bf
cleaning up
Oct 4, 2023
90c0a09
cleaning up
Oct 4, 2023
8476f03
cleaning up
Oct 4, 2023
07eb112
cleaning up
Oct 4, 2023
a57b4f5
merge
Oct 5, 2023
4d82798
comments #1
Oct 5, 2023
ba5ad1b
comments #2
Oct 5, 2023
6e2644f
comments #2
Oct 5, 2023
fbf68dc
comments #2
Oct 5, 2023
25e3032
comments #3
Oct 5, 2023
4439423
comments #3
Oct 5, 2023
183352e
comments #4
Oct 5, 2023
2a7df24
comments #5
Oct 6, 2023
9c33f1f
comments #5
Oct 6, 2023
532be31
use latest cfl package
SKairinos Oct 16, 2023
f797771
quick save
SKairinos Oct 16, 2023
d7eafb3
update user api
SKairinos Oct 16, 2023
09755e6
new user endpoints
SKairinos Oct 17, 2023
86eed3b
new user endpoints pt.2
SKairinos Oct 17, 2023
26943e1
new cfl package
SKairinos Oct 19, 2023
455eb6f
new cfl package
SKairinos Oct 19, 2023
236139c
fix formatting
SKairinos Oct 19, 2023
0cb5246
remove required
SKairinos Oct 19, 2023
3c0c90c
handle response errors
SKairinos Oct 19, 2023
4f0b3e5
classes endpoints
SKairinos Oct 19, 2023
809ba04
fix type
SKairinos Oct 19, 2023
1f01127
update userId type pt. 2
SKairinos Oct 19, 2023
d89122c
can read and write password
SKairinos Oct 19, 2023
c630c37
fix formatting
SKairinos Oct 19, 2023
5556609
page to student credentials
SKairinos Oct 19, 2023
b1aacfc
name defaults to firstName
SKairinos Oct 19, 2023
82486aa
fix: update api endpoints
SKairinos Oct 20, 2023
a0377d6
override user urls
SKairinos Oct 22, 2023
4af2989
make teacher and student fields editable
SKairinos Oct 22, 2023
7726ddb
fix onboarding
SKairinos Oct 23, 2023
380980c
update api endpoints
SKairinos Oct 23, 2023
84c9588
simplify edit student pages
SKairinos Oct 23, 2023
548e508
fix type errors
SKairinos Oct 23, 2023
c16c4ef
fix type
SKairinos Oct 24, 2023
505d651
use new cfl packages
SKairinos Oct 24, 2023
4ea307a
feedback
SKairinos Oct 24, 2023
54768ec
merge from dev
SKairinos Oct 24, 2023
e72036f
userId should be a number
SKairinos Oct 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ google-cloud-logging = "==1.*"
google-auth = "==2.*"
google-cloud-container = "==2.3.0"
"django-anymail[amazon_ses]" = "==7.0.*"
codeforlife = {ref = "v0.8.0", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
codeforlife = {ref = "v0.8.4", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"}
django = "==3.2.20"
djangorestframework = "==3.13.1"
django-cors-headers = "==4.1.0"
Expand Down
739 changes: 386 additions & 353 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion backend/portal/helpers/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def get_domain(request):
"""
Returns the domain of the request
"""

return (
"http://localhost:3000"
if os.environ.get("DJANGO_DEBUG") == "True"
Expand Down
3 changes: 3 additions & 0 deletions backend/portal/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .klass import ClassSerializer
from .school import SchoolSerializer
from .user import UserSerializer
6 changes: 6 additions & 0 deletions backend/portal/serializers/klass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from codeforlife.user.serializers import ClassSerializer as _ClassSerializer


class ClassSerializer(_ClassSerializer):
class Meta(_ClassSerializer.Meta):
pass
6 changes: 6 additions & 0 deletions backend/portal/serializers/school.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from codeforlife.user.serializers import SchoolSerializer as _SchoolSerializer


class SchoolSerializer(_SchoolSerializer):
class Meta(_SchoolSerializer.Meta):
pass
16 changes: 16 additions & 0 deletions backend/portal/serializers/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from codeforlife.user.serializers import UserSerializer as _UserSerializer
from rest_framework import serializers


class UserSerializer(_UserSerializer):
current_password = serializers.CharField(write_only=True)

class Meta(_UserSerializer.Meta):
extra_kwargs = {
**_UserSerializer.Meta.extra_kwargs,
"username": {"read_only": True},
"isActive": {"read_only": True},
"isStaff": {"read_only": True},
"dateJoined": {"read_only": True},
"lastLogin": {"read_only": True},
}
10 changes: 9 additions & 1 deletion backend/portal/urls/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
from django.urls import include, path
from rest_framework.routers import DefaultRouter

from ..views import ClassViewSet, SchoolViewSet, UserViewSet
from .admin import urlpatterns as admin_urlpatterns
from .cron import urlpatterns as cron_urlpatterns
from .dotmailer import urlpatterns as dotmailer_urlpatterns
from .email import urlpatterns as email_urlpatterns
from .home import urlpatterns as home_urlpatterns
from .organisation import urlpatterns as organisation_urlpatterns
from .teacher.dashboard import urlpatterns as teach_dashboard_urlpatterns
from .registration import urlpatterns as registration_urlpatterns
from .student import urlpatterns as student_urlpatterns
from .teacher import urlpatterns as teacher_urlpatterns
from .teacher.dashboard import urlpatterns as teach_dashboard_urlpatterns

router = DefaultRouter()
router.register("classes", ClassViewSet, basename="class")
router.register("users", UserViewSet, basename="user")
router.register("schools", SchoolViewSet, basename="school")

urlpatterns = [
path("cron/", include(cron_urlpatterns)),
path("", include(router.urls)),
*dotmailer_urlpatterns,
*email_urlpatterns,
*home_urlpatterns,
Expand Down
6 changes: 6 additions & 0 deletions backend/portal/urls/teacher/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
create_new_class,
get_student_request_data,
get_students_from_access_code,
get_student_details,
)

from ...helpers.regexes import ACCESS_CODE_REGEX
Expand Down Expand Up @@ -88,4 +89,9 @@
get_students_from_access_code,
name="get_students_from_acccess_code",
),
re_path(
r"^class/student/(?P<student_id>[0-9]+)/$",
get_student_details,
name="get_student_details",
),
]
12 changes: 12 additions & 0 deletions backend/portal/urls/teacher/teach.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
teacher_edit_class,
teacher_delete_class,
teacher_move_class,
teacher_edit_student,
teacher_print_reminder_cards,
)


Expand All @@ -24,4 +26,14 @@
teacher_move_class,
name="teacher_move_class",
),
path(
"student/edit/<int:pk>",
teacher_edit_student,
name="teacher_edit_student",
),
re_path(
rf"onboarding-class/(?P<access_code>{ACCESS_CODE_REGEX})/print-reminder-cards/",
teacher_print_reminder_cards,
name="teacher_print_reminder_cards",
),
]
3 changes: 3 additions & 0 deletions backend/portal/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .klass import ClassViewSet
from .school import SchoolViewSet
from .user import UserViewSet
8 changes: 8 additions & 0 deletions backend/portal/views/klass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from codeforlife.user.views import ClassViewSet as _ClassViewSet

from ..serializers import ClassSerializer


class ClassViewSet(_ClassViewSet):
http_method_names = ["get", "post", "patch", "delete"]
serializer_class = ClassSerializer
8 changes: 8 additions & 0 deletions backend/portal/views/school.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from codeforlife.user.views import SchoolViewSet as _SchoolViewSet

from ..serializers import SchoolSerializer


class SchoolViewSet(_SchoolViewSet):
http_method_names = ["get", "post", "patch"]
serializer_class = SchoolSerializer
41 changes: 38 additions & 3 deletions backend/portal/views/teacher/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from django.contrib.auth import logout
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.models import User
from django.core import serializers
from django.db.models import F, Value
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import F
from django.http import (
Http404,
HttpResponse,
Expand Down Expand Up @@ -68,10 +68,12 @@

@login_required(login_url=reverse_lazy("teacher_login"))
def get_students_from_access_code(request, access_code):
check_teacher_authorised(request, request.user.new_teacher)
student_class = Class.objects.get(access_code=access_code)
check_teacher_authorised(request, student_class.teacher)
students_query = Student.objects.filter(
class_field__access_code=access_code
)
# TODO: make this into a method for the student so we can reuse it
students = [
{
"id": student.id,
Expand All @@ -94,6 +96,39 @@ def get_students_from_access_code(request, access_code):
return JsonResponse({"students_per_access_code": students})


def get_student_details(request, student_id):
student = get_object_or_404(Student, id=student_id)
try:
student_class = Class.objects.get(
access_code=student.class_field.access_code
)
check_teacher_authorised(request, student_class.teacher)
except (ObjectDoesNotExist, AttributeError) as error:
return JsonResponse({"error": str(error)})
# TODO: make this into a method for the student so we can reuse it
return JsonResponse(
{
"student": {
"id": student.id,
"class_field": getattr(student.class_field, "id", 0),
"new_user": {
"id": getattr(student.new_user, "id", 0),
"first_name": getattr(student.new_user, "first_name", ""),
"last_name": getattr(student.new_user, "last_name", ""),
},
"pending_class_request": getattr(
student.pending_class_request, "id", 0
),
"blocked_time": student.blocked_time.strftime(
"%Y-%m-%d %H:%M:%S"
)
if student.blocked_time
else "",
}
}
)


def _get_update_account_rate(group, request):
"""
Custom rate which checks in a POST request is performed on the update
Expand Down
Loading
Loading