Add due_dates rest endpoint for dashboard
This commit is contained in:
parent
bfdacfec62
commit
50c35b7100
|
|
@ -44,6 +44,7 @@ from vbv_lernwelt.dashboard.views import (
|
||||||
get_dashboard_persons,
|
get_dashboard_persons,
|
||||||
get_mentee_count,
|
get_mentee_count,
|
||||||
get_mentor_open_tasks_count,
|
get_mentor_open_tasks_count,
|
||||||
|
get_dashboard_due_dates,
|
||||||
)
|
)
|
||||||
from vbv_lernwelt.edoniq_test.views import (
|
from vbv_lernwelt.edoniq_test.views import (
|
||||||
export_students,
|
export_students,
|
||||||
|
|
@ -124,6 +125,7 @@ urlpatterns = [
|
||||||
|
|
||||||
# dashboard
|
# dashboard
|
||||||
path(r"api/dashboard/persons/", get_dashboard_persons, name="get_dashboard_persons"),
|
path(r"api/dashboard/persons/", get_dashboard_persons, name="get_dashboard_persons"),
|
||||||
|
path(r"api/dashboard/duedates/", get_dashboard_due_dates, name="get_dashboard_due_dates"),
|
||||||
path(r"api/dashboard/config/", get_dashboard_config, name="get_dashboard_config"),
|
path(r"api/dashboard/config/", get_dashboard_config, name="get_dashboard_config"),
|
||||||
path(r"api/dashboard/course/<str:course_id>/mentees/", get_mentee_count, name="get_mentee_count"),
|
path(r"api/dashboard/course/<str:course_id>/mentees/", get_mentee_count, name="get_mentee_count"),
|
||||||
path(r"api/dashboard/course/<str:course_id>/open_tasks/", get_mentor_open_tasks_count,
|
path(r"api/dashboard/course/<str:course_id>/open_tasks/", get_mentor_open_tasks_count,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from dataclasses import asdict, dataclass
|
from dataclasses import asdict, dataclass
|
||||||
|
from datetime import date
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import List, Set
|
from typing import List, Set
|
||||||
|
|
||||||
|
|
@ -18,6 +19,8 @@ from vbv_lernwelt.course.models import (
|
||||||
)
|
)
|
||||||
from vbv_lernwelt.course.views import logger
|
from vbv_lernwelt.course.views import logger
|
||||||
from vbv_lernwelt.course_session_group.models import CourseSessionGroup
|
from vbv_lernwelt.course_session_group.models import CourseSessionGroup
|
||||||
|
from vbv_lernwelt.duedate.models import DueDate
|
||||||
|
from vbv_lernwelt.duedate.serializers import DueDateSerializer
|
||||||
from vbv_lernwelt.learning_mentor.models import LearningMentor
|
from vbv_lernwelt.learning_mentor.models import LearningMentor
|
||||||
from vbv_lernwelt.self_evaluation_feedback.models import SelfEvaluationFeedback
|
from vbv_lernwelt.self_evaluation_feedback.models import SelfEvaluationFeedback
|
||||||
|
|
||||||
|
|
@ -235,6 +238,53 @@ def get_dashboard_persons(request):
|
||||||
def get_dashboard_due_dates(request):
|
def get_dashboard_due_dates(request):
|
||||||
try:
|
try:
|
||||||
course_sessions = get_course_sessions_with_roles_for_user(request.user)
|
course_sessions = get_course_sessions_with_roles_for_user(request.user)
|
||||||
|
course_session_ids = [cs.id for cs in course_sessions]
|
||||||
|
|
||||||
|
all_due_dates = DueDate.objects.filter(
|
||||||
|
course_session__id__in=course_session_ids
|
||||||
|
)
|
||||||
|
|
||||||
|
# filter only future due dates
|
||||||
|
due_dates = []
|
||||||
|
today = date.today()
|
||||||
|
for due_date in all_due_dates:
|
||||||
|
if due_date.end:
|
||||||
|
if due_date.end.date() >= today:
|
||||||
|
due_dates.append(due_date)
|
||||||
|
elif due_date.start:
|
||||||
|
if due_date.start.date() >= today:
|
||||||
|
due_dates.append(due_date)
|
||||||
|
|
||||||
|
due_dates.sort(key=lambda x: x.start)
|
||||||
|
|
||||||
|
# find course session by id in `course_sessions`
|
||||||
|
|
||||||
|
result_due_dates = []
|
||||||
|
for due_date in due_dates:
|
||||||
|
data = DueDateSerializer(due_date).data
|
||||||
|
|
||||||
|
cs = next(
|
||||||
|
course_session
|
||||||
|
for course_session in course_sessions
|
||||||
|
if course_session.id == due_date.course_session.id
|
||||||
|
)
|
||||||
|
if cs:
|
||||||
|
data["course_session"] = {
|
||||||
|
"id": str(cs.id),
|
||||||
|
"session_title": cs.title,
|
||||||
|
"course_id": str(cs.course.id),
|
||||||
|
"course_title": cs.course.title,
|
||||||
|
"course_slug": cs.course.slug,
|
||||||
|
"user_role": user_role(cs.roles),
|
||||||
|
"is_uk": cs.course.configuration.is_uk,
|
||||||
|
"is_vv": cs.course.configuration.is_vv,
|
||||||
|
}
|
||||||
|
result_due_dates.append(data)
|
||||||
|
|
||||||
|
return Response(
|
||||||
|
status=200,
|
||||||
|
data=result_due_dates,
|
||||||
|
)
|
||||||
|
|
||||||
except PermissionDenied as e:
|
except PermissionDenied as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
@ -395,9 +445,7 @@ def get_mentor_open_tasks_count(request, course_id: str):
|
||||||
return Response(
|
return Response(
|
||||||
status=200,
|
status=200,
|
||||||
data={
|
data={
|
||||||
"open_task_count": _get_mentor_open_tasks_count(
|
"open_task_count": _get_mentor_open_tasks_count(course_id, request.user) # noqa
|
||||||
course_id, request.user
|
|
||||||
) # noqa
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
except PermissionDenied as e:
|
except PermissionDenied as e:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue