65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
from django.shortcuts import redirect
|
|
from rest_framework.decorators import api_view, permission_classes
|
|
from rest_framework.generics import get_object_or_404
|
|
from rest_framework.permissions import IsAuthenticated
|
|
from rest_framework.response import Response
|
|
|
|
from vbv_lernwelt.core.serializers import UserSerializer
|
|
from vbv_lernwelt.course.models import CourseSession
|
|
from vbv_lernwelt.learning_mentor.content.praxis_assignment import (
|
|
get_praxis_assignments,
|
|
)
|
|
from vbv_lernwelt.learning_mentor.models import LearningMentor
|
|
from vbv_lernwelt.learning_mentor.serializers import PraxisAssignmentStatusSerializer
|
|
from vbv_lernwelt.learnpath.models import Circle
|
|
|
|
|
|
@api_view(["GET"])
|
|
@permission_classes([IsAuthenticated])
|
|
def mentor_summary(request, course_session_id: int):
|
|
course_session = CourseSession.objects.get(id=course_session_id)
|
|
|
|
mentor = get_object_or_404(
|
|
LearningMentor, mentor=request.user, course=course_session.course
|
|
)
|
|
|
|
participants = mentor.participants.filter(course_session=course_session)
|
|
users = [p.user for p in participants]
|
|
|
|
praxis_assignments, circle_ids = get_praxis_assignments(course_session, users)
|
|
|
|
circles = Circle.objects.filter(id__in=circle_ids).values("id", "title")
|
|
|
|
return Response(
|
|
{
|
|
"participants": [UserSerializer(user).data for user in users],
|
|
"circles": list(circles),
|
|
"praxis_assignments": PraxisAssignmentStatusSerializer(
|
|
praxis_assignments, many=True
|
|
).data,
|
|
}
|
|
)
|
|
|
|
|
|
@api_view(["GET"])
|
|
@permission_classes([IsAuthenticated])
|
|
def list_invitations(request, course_session_id: int):
|
|
pass
|
|
|
|
|
|
@api_view(["POST"])
|
|
@permission_classes([IsAuthenticated])
|
|
def create_invitation(request, course_session_id: int):
|
|
# Validate request
|
|
# Create invitation
|
|
# Send email
|
|
pass
|
|
|
|
|
|
@api_view(["GET"])
|
|
def accept_invitation(request, course_session_id: int):
|
|
if not request.user.is_authenticated:
|
|
return redirect(f"/onboarding/vv/account/create?next={request.path}")
|
|
|
|
# Validate invitation
|