Skip to content

Commit

Permalink
Use the json_iso_utc serializer in all dashboard endpoints
Browse files Browse the repository at this point in the history
This will return dates with timezone information
  • Loading branch information
marcospri committed Oct 4, 2024
1 parent 464b8fa commit 1773877
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
3 changes: 2 additions & 1 deletion lms/js_config_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Making this a top level module to avoid circular dependency problems.
"""

from datetime import datetime
from typing import Literal, NotRequired, TypedDict


Expand Down Expand Up @@ -63,7 +64,7 @@ class AutoGradingGrade(TypedDict):
last_grade: float | None
"""Last grade that was succefully sync to the LMS."""

last_grade_date: str | None
last_grade_date: datetime | None
"""Time when `last_grade` was synced to the LMS."""


Expand Down
12 changes: 6 additions & 6 deletions lms/models/_mixins/created_updated.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from datetime import datetime

import sqlalchemy as sa
from sqlalchemy.orm import Mapped, mapped_column


class CreatedUpdatedMixin:
created = sa.Column(sa.DateTime(), server_default=sa.func.now(), nullable=False)
updated = sa.Column(
sa.DateTime(),
server_default=sa.func.now(),
onupdate=sa.func.now(),
nullable=False,
created: Mapped[datetime] = mapped_column(server_default=sa.func.now())
updated: Mapped[datetime] = mapped_column(
server_default=sa.func.now(), onupdate=sa.func.now()
)
8 changes: 4 additions & 4 deletions lms/views/dashboard/api/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, request) -> None:
@view_config(
route_name="api.dashboard.courses",
request_method="GET",
renderer="json",
renderer="json_iso_utc",
permission=Permissions.DASHBOARD_VIEW,
schema=ListCoursesSchema,
)
Expand Down Expand Up @@ -85,7 +85,7 @@ def courses(self) -> APICourses:
@view_config(
route_name="api.dashboard.courses.metrics",
request_method="GET",
renderer="json",
renderer="json_iso_utc",
permission=Permissions.DASHBOARD_VIEW,
schema=CoursesMetricsSchema,
)
Expand Down Expand Up @@ -127,7 +127,7 @@ def courses_metrics(self) -> APICourses:
title=course.lms_name,
course_metrics=CourseMetrics(
assignments=courses_assignments_counts.get(course.id, 0),
last_launched=course.updated.isoformat(),
last_launched=course.updated,
),
)
for course in courses
Expand All @@ -137,7 +137,7 @@ def courses_metrics(self) -> APICourses:
@view_config(
route_name="api.dashboard.course",
request_method="GET",
renderer="json",
renderer="json_iso_utc",
permission=Permissions.DASHBOARD_VIEW,
)
def course(self) -> APICourse:
Expand Down
4 changes: 2 additions & 2 deletions lms/views/dashboard/api/grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, request) -> None:
@view_config(
route_name="api.dashboard.assignments.grading.sync",
request_method="POST",
renderer="json",
renderer="json_iso_utc",
permission=Permissions.GRADE_ASSIGNMENT,
schema=AutoGradeSyncSchema,
)
Expand Down Expand Up @@ -80,7 +80,7 @@ def create_grading_sync(self):
@view_config(
route_name="api.dashboard.assignments.grading.sync",
request_method="GET",
renderer="json",
renderer="json_iso_utc",
permission=Permissions.GRADE_ASSIGNMENT,
)
def get_grading_sync(self):
Expand Down
6 changes: 3 additions & 3 deletions lms/views/dashboard/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, request) -> None:
@view_config(
route_name="api.dashboard.students",
request_method="GET",
renderer="json",
renderer="json_iso_utc",
permission=Permissions.DASHBOARD_VIEW,
schema=ListUsersSchema,
)
Expand Down Expand Up @@ -115,7 +115,7 @@ def students(self) -> APIStudents:
@view_config(
route_name="api.dashboard.students.metrics",
request_method="GET",
renderer="json",
renderer="json_iso_utc",
permission=Permissions.DASHBOARD_VIEW,
schema=UsersMetricsSchema,
)
Expand Down Expand Up @@ -215,7 +215,7 @@ def _add_auto_grading_data(
}
if last_grade := last_sync_grades.get(api_student["h_userid"]):
auto_grading_grade["last_grade"] = last_grade.grade
auto_grading_grade["last_grade_date"] = last_grade.updated.isoformat()
auto_grading_grade["last_grade_date"] = last_grade.updated

api_student["auto_grading_grade"] = auto_grading_grade

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lms/views/dashboard/api/course_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_course_metrics(
"title": c.lms_name,
"course_metrics": {
"assignments": assignment_service.get_courses_assignments_count.return_value.get.return_value,
"last_launched": c.updated.isoformat(),
"last_launched": c.updated,
},
}
for c in courses
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lms/views/dashboard/api/user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def test_students_metrics_with_auto_grading( # pylint:disable=too-many-locals
"last_grade": last_grades.get.return_value.grade
if with_last_grade
else None,
"last_grade_date": last_grades.get.return_value.updated.isoformat.return_value
"last_grade_date": last_grades.get.return_value.updated
if with_last_grade
else None,
}
Expand Down

0 comments on commit 1773877

Please sign in to comment.