User course_session and course `id`s as string
This commit is contained in:
parent
46a2f6a3ba
commit
bfdacfec62
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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]:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue