From bfdacfec62ae5d1c393c871e3304fe374fda6063 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Thu, 18 Apr 2024 17:39:58 +0200 Subject: [PATCH] User course_session and course `id`s as string --- .../pages/dashboard/DashboardPersonsPage.vue | 4 +-- client/src/services/dashboard.ts | 4 +-- server/vbv_lernwelt/dashboard/views.py | 24 ++++++++++---- server/vbv_lernwelt/duedate/models.py | 33 ------------------- 4 files changed, 22 insertions(+), 43 deletions(-) diff --git a/client/src/pages/dashboard/DashboardPersonsPage.vue b/client/src/pages/dashboard/DashboardPersonsPage.vue index ac944f5a..821302e9 100644 --- a/client/src/pages/dashboard/DashboardPersonsPage.vue +++ b/client/src/pages/dashboard/DashboardPersonsPage.vue @@ -10,10 +10,10 @@ import type { DashboardPersonCourseSessionType } from "@/services/dashboard"; log.debug("DashboardPersonsPage created"); -const UNFILTERED = 0; +const UNFILTERED = Number.MAX_SAFE_INTEGER.toString(); type MenuItem = { - id: number; + id: string; name: string; }; diff --git a/client/src/services/dashboard.ts b/client/src/services/dashboard.ts index fae8181e..18d3526b 100644 --- a/client/src/services/dashboard.ts +++ b/client/src/services/dashboard.ts @@ -38,9 +38,9 @@ export type WidgetType = | "UKStatisticsWidget"; export type DashboardPersonCourseSessionType = { - id: number; + id: string; session_title: string; - course_id: number; + course_id: string; course_title: string; course_slug: string; user_role: DashboardPersonRoleType; diff --git a/server/vbv_lernwelt/dashboard/views.py b/server/vbv_lernwelt/dashboard/views.py index fb68f6ce..ca57631e 100644 --- a/server/vbv_lernwelt/dashboard/views.py +++ b/server/vbv_lernwelt/dashboard/views.py @@ -141,9 +141,9 @@ def get_dashboard_persons(request): "email": csu.user.email, "course_sessions": [ { - "id": cs.id, + "id": str(cs.id), "session_title": cs.title, - "course_id": cs.course.id, + "course_id": str(cs.course.id), "course_title": cs.course.title, "course_slug": cs.course.slug, "user_role": csu.role, @@ -163,9 +163,9 @@ def get_dashboard_persons(request): for participant in lm.participants.all(): course_session_entry = { - "id": cs.id, + "id": str(cs.id), "session_title": cs.title, - "course_id": cs.course.id, + "course_id": str(cs.course.id), "course_title": cs.course.title, "course_slug": cs.course.slug, "user_role": "LEARNING_MENTEE", @@ -195,9 +195,9 @@ def get_dashboard_persons(request): for mentor_relation in mentor_relation_qs: cs = mentor_relation.course_session course_session_entry = { - "id": cs.id, + "id": str(cs.id), "session_title": cs.title, - "course_id": cs.course.id, + "course_id": str(cs.course.id), "course_title": cs.course.title, "course_slug": cs.course.slug, "user_role": "LEARNING_MENTOR", @@ -231,6 +231,18 @@ def get_dashboard_persons(request): return Response({"error": str(e)}, status=404) +@api_view(["GET"]) +def get_dashboard_due_dates(request): + try: + course_sessions = get_course_sessions_with_roles_for_user(request.user) + + except PermissionDenied as e: + raise e + except Exception as e: + logger.error(e, exc_info=True) + return Response({"error": str(e)}, status=404) + + def get_widgets_for_course( role_key: RoleKeyType, is_uk: bool, is_vv: bool, is_mentor: bool ) -> List[str]: diff --git a/server/vbv_lernwelt/duedate/models.py b/server/vbv_lernwelt/duedate/models.py index 14e2f9d6..3bfe6ee5 100644 --- a/server/vbv_lernwelt/duedate/models.py +++ b/server/vbv_lernwelt/duedate/models.py @@ -4,9 +4,6 @@ from django.db import models from django.utils import timezone from wagtail.models import Page -from vbv_lernwelt.core.models import User -from vbv_lernwelt.course.models import CourseSession - class DueDate(models.Model): start = models.DateTimeField( @@ -125,33 +122,3 @@ class DueDate(models.Model): except Exception: # noop return None - - @classmethod - def get_users_next_events_qs( - cls, user: User, course_session: CourseSession = None, limit=10 - ): - """ - Returns a queryset of all due dates that are relevant for the given user. - If course_session is given, only due dates for that course_session are returned. - The user is determined by via a course session user of a course_assignment. - - """ - qs = cls.get_next_due_dates_qs() - - if course_session: - qs = qs.filter( - course_session=course_session, - course_session__course_assignment__user=user, - ) - else: - qs = qs.filter(course_session__course_assignment__user=user) - - qs = qs.order_by("start")[:limit] - - return qs - - @classmethod - def get_next_due_dates_qs(cls): - now = timezone.now() - qs = cls.objects.filter(start__gte=now) - return qs