WIP: Remove GraphQL code
This commit is contained in:
parent
4a982d8af2
commit
265bd01b79
|
|
@ -181,7 +181,6 @@ type CourseProgressType {
|
||||||
session_to_continue_id: ID
|
session_to_continue_id: ID
|
||||||
competence: ProgressDashboardCompetenceType
|
competence: ProgressDashboardCompetenceType
|
||||||
assignment: ProgressDashboardAssignmentType
|
assignment: ProgressDashboardAssignmentType
|
||||||
ui_config: UIConfigType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProgressDashboardCompetenceType {
|
type ProgressDashboardCompetenceType {
|
||||||
|
|
@ -198,30 +197,6 @@ type ProgressDashboardAssignmentType {
|
||||||
points_achieved_count: Int!
|
points_achieved_count: Int!
|
||||||
}
|
}
|
||||||
|
|
||||||
type UIConfigType {
|
|
||||||
_id: ID!
|
|
||||||
role_key: RoleKeyType!
|
|
||||||
widgets: [WidgetType!]!
|
|
||||||
has_preview: Boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
enum RoleKeyType {
|
|
||||||
MEMBER
|
|
||||||
MENTOR_VV
|
|
||||||
MENTOR_UK
|
|
||||||
SUPERVISOR
|
|
||||||
TRAINER
|
|
||||||
}
|
|
||||||
|
|
||||||
enum WidgetType {
|
|
||||||
PROGRESS_WIDGET
|
|
||||||
COMPETENCE_WIDGET
|
|
||||||
MENTOR_TASKS_WIDGET
|
|
||||||
MENTOR_PERSON_WIDGET
|
|
||||||
MENTOR_COMPETENCE_WIDGET
|
|
||||||
COMPETENCE_CERTIFICATE_WIDGET
|
|
||||||
}
|
|
||||||
|
|
||||||
type DashboardConfigType {
|
type DashboardConfigType {
|
||||||
id: ID!
|
id: ID!
|
||||||
name: String!
|
name: String!
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ from vbv_lernwelt.dashboard.graphql.types.dashboard import (
|
||||||
CourseStatisticsType,
|
CourseStatisticsType,
|
||||||
DashboardConfigType,
|
DashboardConfigType,
|
||||||
DashboardType,
|
DashboardType,
|
||||||
get_ui_config_for_course,
|
|
||||||
ProgressDashboardAssignmentType,
|
ProgressDashboardAssignmentType,
|
||||||
ProgressDashboardCompetenceType,
|
ProgressDashboardCompetenceType,
|
||||||
)
|
)
|
||||||
|
|
@ -139,7 +138,6 @@ class DashboardQuery(graphene.ObjectType):
|
||||||
user = info.context.user
|
user = info.context.user
|
||||||
course = Course.objects.get(id=course_id)
|
course = Course.objects.get(id=course_id)
|
||||||
setattr(info.context, "course", course)
|
setattr(info.context, "course", course)
|
||||||
return CourseProgressType()
|
|
||||||
|
|
||||||
newest: CourseSession | None = None
|
newest: CourseSession | None = None
|
||||||
course_session_for_user: List[str] = []
|
course_session_for_user: List[str] = []
|
||||||
|
|
@ -195,7 +193,6 @@ class DashboardQuery(graphene.ObjectType):
|
||||||
points_max_count=int(points_max_count), # noqa
|
points_max_count=int(points_max_count), # noqa
|
||||||
points_achieved_count=int(points_achieved_count), # noqa
|
points_achieved_count=int(points_achieved_count), # noqa
|
||||||
),
|
),
|
||||||
widgets=get_ui_config_for_course(course, user), # noqa
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,8 @@
|
||||||
from typing import Dict, List, Set, Tuple
|
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
from graphene import Enum
|
from graphene import Enum
|
||||||
|
|
||||||
from vbv_lernwelt.assignment.models import (
|
|
||||||
AssignmentCompletion,
|
|
||||||
AssignmentCompletionStatus,
|
|
||||||
)
|
|
||||||
from vbv_lernwelt.core.models import User
|
|
||||||
from vbv_lernwelt.course.consts import UK_COURSE_IDS
|
|
||||||
from vbv_lernwelt.course.graphql.types import CourseConfigurationObjectType
|
from vbv_lernwelt.course.graphql.types import CourseConfigurationObjectType
|
||||||
from vbv_lernwelt.course.models import Course, CourseSession, CourseSessionUser
|
from vbv_lernwelt.course.models import CourseSession, CourseSessionUser
|
||||||
from vbv_lernwelt.dashboard.graphql.types.assignment import (
|
from vbv_lernwelt.dashboard.graphql.types.assignment import (
|
||||||
assignments,
|
assignments,
|
||||||
AssignmentsStatisticsType,
|
AssignmentsStatisticsType,
|
||||||
|
|
@ -28,11 +20,6 @@ from vbv_lernwelt.dashboard.graphql.types.feedback import (
|
||||||
feedback_responses,
|
feedback_responses,
|
||||||
FeedbackStatisticsResponsesType,
|
FeedbackStatisticsResponsesType,
|
||||||
)
|
)
|
||||||
from vbv_lernwelt.iam.permissions import (
|
|
||||||
can_view_course_session,
|
|
||||||
can_view_course_session_progress,
|
|
||||||
)
|
|
||||||
from vbv_lernwelt.learning_mentor.models import LearningMentor
|
|
||||||
from vbv_lernwelt.learnpath.models import Circle
|
from vbv_lernwelt.learnpath.models import Circle
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -70,23 +57,6 @@ class DashboardType(Enum):
|
||||||
PRAXISBILDNER_DASHBOARD = "PraxisbildnerDashboard"
|
PRAXISBILDNER_DASHBOARD = "PraxisbildnerDashboard"
|
||||||
|
|
||||||
|
|
||||||
class WidgetType(Enum):
|
|
||||||
PROGRESS_WIDGET = "ProgressWidget"
|
|
||||||
COMPETENCE_WIDGET = "CompetenceWidget"
|
|
||||||
MENTOR_TASKS_WIDGET = "MentorTasksWidget"
|
|
||||||
MENTOR_PERSON_WIDGET = "MentorPersonWidget"
|
|
||||||
MENTOR_COMPETENCE_WIDGET = "MentorCompetenceWidget"
|
|
||||||
COMPETENCE_CERTIFICATE_WIDGET = "CompetenceCertificateWidget"
|
|
||||||
|
|
||||||
|
|
||||||
class RoleKeyType(Enum):
|
|
||||||
MEMBER = "Member"
|
|
||||||
MENTOR_VV = "MentorVV"
|
|
||||||
MENTOR_UK = "MentorUK"
|
|
||||||
SUPERVISOR = "Supervisor"
|
|
||||||
TRAINER = "Trainer"
|
|
||||||
|
|
||||||
|
|
||||||
class DashboardConfigType(graphene.ObjectType):
|
class DashboardConfigType(graphene.ObjectType):
|
||||||
id = graphene.ID(required=True)
|
id = graphene.ID(required=True)
|
||||||
name = graphene.String(required=True)
|
name = graphene.String(required=True)
|
||||||
|
|
@ -109,100 +79,12 @@ class ProgressDashboardAssignmentType(graphene.ObjectType):
|
||||||
points_achieved_count = graphene.Int(required=True)
|
points_achieved_count = graphene.Int(required=True)
|
||||||
|
|
||||||
|
|
||||||
class UIConfigType(graphene.ObjectType):
|
|
||||||
_id = graphene.ID(required=True)
|
|
||||||
role_key = graphene.Field(RoleKeyType, required=True)
|
|
||||||
widgets = graphene.List(graphene.NonNull(WidgetType), required=True)
|
|
||||||
has_preview = graphene.Boolean(required=False)
|
|
||||||
|
|
||||||
|
|
||||||
class CourseProgressType(graphene.ObjectType):
|
class CourseProgressType(graphene.ObjectType):
|
||||||
_id = graphene.ID(required=True)
|
_id = graphene.ID(required=True)
|
||||||
course_id = graphene.ID(required=True)
|
course_id = graphene.ID(required=True)
|
||||||
session_to_continue_id = graphene.ID(required=False)
|
session_to_continue_id = graphene.ID(required=False)
|
||||||
competence = graphene.Field(ProgressDashboardCompetenceType, required=False)
|
competence = graphene.Field(ProgressDashboardCompetenceType, required=False)
|
||||||
assignment = graphene.Field(ProgressDashboardAssignmentType, required=False)
|
assignment = graphene.Field(ProgressDashboardAssignmentType, required=False)
|
||||||
ui_config = graphene.Field(UIConfigType, required=False)
|
|
||||||
|
|
||||||
def resolve__id(root, info):
|
|
||||||
return info.context.course.id
|
|
||||||
|
|
||||||
def resolve_course_id(root, info):
|
|
||||||
return info.context.course.id
|
|
||||||
|
|
||||||
def resolve_session_to_continue_id(root, info):
|
|
||||||
newest, _course_session_for_user = root._get_newest_cs_and_cs_for_user(
|
|
||||||
info, info.context.course.id, info.context.user
|
|
||||||
)
|
|
||||||
return newest.id if newest else None
|
|
||||||
|
|
||||||
def resolve_assignment(root, info):
|
|
||||||
evaluation_results = AssignmentCompletion.objects.filter(
|
|
||||||
completion_status=AssignmentCompletionStatus.EVALUATION_SUBMITTED.value,
|
|
||||||
assignment_user=info.context.user,
|
|
||||||
course_session__course=info.context.course,
|
|
||||||
).values("evaluation_max_points", "evaluation_points")
|
|
||||||
|
|
||||||
evaluation_results = list(evaluation_results)
|
|
||||||
points_max_count = sum(
|
|
||||||
[result.get("evaluation_max_points", 0) for result in evaluation_results]
|
|
||||||
)
|
|
||||||
points_achieved_count = sum(
|
|
||||||
[result.get("evaluation_points", 0) for result in evaluation_results]
|
|
||||||
)
|
|
||||||
return ProgressDashboardAssignmentType( # noqa
|
|
||||||
_id=info.context.course.id, # noqa
|
|
||||||
total_count=len(evaluation_results), # noqa
|
|
||||||
points_max_count=int(points_max_count), # noqa
|
|
||||||
points_achieved_count=int(points_achieved_count), # noqa
|
|
||||||
)
|
|
||||||
|
|
||||||
def resolve_competence(root, info):
|
|
||||||
newest, course_session_for_user = root._get_newest_cs_and_cs_for_user(
|
|
||||||
info, info.context.course.id, info.context.user
|
|
||||||
)
|
|
||||||
_, success_total, fail_total = competences(
|
|
||||||
course_slug=str(info.context.course.slug),
|
|
||||||
course_session_selection_ids=course_session_for_user,
|
|
||||||
user_selection_ids=[str(info.context.user.id)],
|
|
||||||
)
|
|
||||||
|
|
||||||
return ProgressDashboardCompetenceType( # noqa
|
|
||||||
_id=info.context.course.id, # noqa
|
|
||||||
total_count=success_total + fail_total, # noqa
|
|
||||||
success_count=success_total, # noqa
|
|
||||||
fail_count=fail_total, # noqa
|
|
||||||
)
|
|
||||||
|
|
||||||
def resolve_ui_config(root, info):
|
|
||||||
return get_ui_config_for_course(info.context.course, info.context.user)
|
|
||||||
|
|
||||||
def _get_newest_cs_and_cs_for_user(
|
|
||||||
root, info, course_id: str, user: User
|
|
||||||
) -> Tuple[CourseSession, List[str]]:
|
|
||||||
newest: CourseSession | None = getattr(info.context, "newest", None)
|
|
||||||
course_session_for_user: List[str] = getattr(
|
|
||||||
info.context, "course_session_for_user", []
|
|
||||||
)
|
|
||||||
|
|
||||||
if newest is not None and course_session_for_user:
|
|
||||||
return newest, course_session_for_user
|
|
||||||
|
|
||||||
for course_session in CourseSession.objects.filter(course_id=course_id):
|
|
||||||
if can_view_course_session_progress(
|
|
||||||
user=user, course_session=course_session
|
|
||||||
):
|
|
||||||
course_session_for_user.append(course_session)
|
|
||||||
generation_newest = newest.generation if newest else None
|
|
||||||
if (
|
|
||||||
generation_newest is None
|
|
||||||
or course_session.generation > generation_newest
|
|
||||||
):
|
|
||||||
newest = course_session
|
|
||||||
# cache for use in other resolvers
|
|
||||||
setattr(info.context, "newest", newest)
|
|
||||||
setattr(info.context, "course_session_for_user", course_session_for_user)
|
|
||||||
return newest, course_session_for_user
|
|
||||||
|
|
||||||
|
|
||||||
class CourseStatisticsType(graphene.ObjectType):
|
class CourseStatisticsType(graphene.ObjectType):
|
||||||
|
|
@ -342,66 +224,3 @@ class CourseStatisticsType(graphene.ObjectType):
|
||||||
generations=list(generations), # noqa
|
generations=list(generations), # noqa
|
||||||
circles=circle_data, # noqa
|
circles=circle_data, # noqa
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_ui_config_for_course(course: Course, user: User) -> UIConfigType:
|
|
||||||
widgets = []
|
|
||||||
role_key = None
|
|
||||||
has_preview = False
|
|
||||||
|
|
||||||
course_sessions = CourseSession.objects.filter(
|
|
||||||
course__id=course.id, coursesessionuser__user=user
|
|
||||||
).prefetch_related(
|
|
||||||
"course",
|
|
||||||
"course__configuration",
|
|
||||||
)
|
|
||||||
|
|
||||||
roles_by_course: Dict[Course, Set[DashboardType]] = {}
|
|
||||||
|
|
||||||
learning_mentors = LearningMentor.objects.filter(
|
|
||||||
mentor=user, course_session__course__id=course.id
|
|
||||||
).values_list("course_session__course__id", "id")
|
|
||||||
mentor_course_ids = set([mentor[0] for mentor in learning_mentors])
|
|
||||||
|
|
||||||
# duplicate code
|
|
||||||
for course_session in course_sessions:
|
|
||||||
if can_view_course_session(user=user, course_session=course_session):
|
|
||||||
role = CourseSessionUser.objects.get(
|
|
||||||
course_session=course_session, user=user
|
|
||||||
).role
|
|
||||||
roles_by_course.setdefault(course_session.course, set())
|
|
||||||
roles_by_course[course_session.course].add(role)
|
|
||||||
|
|
||||||
# todo: use permissions
|
|
||||||
for course, roles in roles_by_course.items():
|
|
||||||
if len(roles) == 1:
|
|
||||||
course_role = roles.pop()
|
|
||||||
|
|
||||||
# members
|
|
||||||
if course_role == CourseSessionUser.Role.MEMBER:
|
|
||||||
role_key = RoleKeyType.MEMBER
|
|
||||||
widgets.append(WidgetType.PROGRESS_WIDGET)
|
|
||||||
widgets.append(WidgetType.COMPETENCE_WIDGET)
|
|
||||||
if course.configuration.enable_competence_certificates:
|
|
||||||
widgets.append(WidgetType.COMPETENCE_CERTIFICATE_WIDGET)
|
|
||||||
# mentors
|
|
||||||
if course.id in mentor_course_ids:
|
|
||||||
if not role_key:
|
|
||||||
role_key = (
|
|
||||||
RoleKeyType.MENTOR_UK
|
|
||||||
if course.id in UK_COURSE_IDS
|
|
||||||
else RoleKeyType.MENTOR_VV
|
|
||||||
)
|
|
||||||
has_preview = True
|
|
||||||
widgets.append(WidgetType.MENTOR_TASKS_WIDGET)
|
|
||||||
widgets.append(WidgetType.MENTOR_PERSON_WIDGET)
|
|
||||||
if course.configuration.enable_competence_certificates:
|
|
||||||
widgets.append(WidgetType.MENTOR_COMPETENCE_WIDGET)
|
|
||||||
|
|
||||||
# todo: supervisors
|
|
||||||
return UIConfigType(
|
|
||||||
_id=f"{course.id}_{user.id}", # noqa
|
|
||||||
role_key=role_key, # noqa,
|
|
||||||
widgets=widgets, # noqa
|
|
||||||
has_preview=has_preview, # noqa
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from dataclasses import asdict, dataclass
|
from dataclasses import asdict, dataclass
|
||||||
|
from enum import Enum
|
||||||
from typing import List, Set
|
from typing import List, Set
|
||||||
|
|
||||||
from rest_framework.decorators import api_view
|
from rest_framework.decorators import api_view
|
||||||
|
|
@ -9,10 +10,26 @@ from vbv_lernwelt.core.models import User
|
||||||
from vbv_lernwelt.course.models import CourseSession, CourseSessionUser
|
from vbv_lernwelt.course.models import CourseSession, CourseSessionUser
|
||||||
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.dashboard.graphql.types.dashboard import RoleKeyType, WidgetType
|
|
||||||
from vbv_lernwelt.learning_mentor.models import LearningMentor
|
from vbv_lernwelt.learning_mentor.models import LearningMentor
|
||||||
|
|
||||||
|
|
||||||
|
class WidgetType(Enum):
|
||||||
|
PROGRESS_WIDGET = "ProgressWidget"
|
||||||
|
COMPETENCE_WIDGET = "CompetenceWidget"
|
||||||
|
MENTOR_TASKS_WIDGET = "MentorTasksWidget"
|
||||||
|
MENTOR_PERSON_WIDGET = "MentorPersonWidget"
|
||||||
|
MENTOR_COMPETENCE_WIDGET = "MentorCompetenceWidget"
|
||||||
|
COMPETENCE_CERTIFICATE_WIDGET = "CompetenceCertificateWidget"
|
||||||
|
|
||||||
|
|
||||||
|
class RoleKeyType(Enum):
|
||||||
|
MEMBER = "Member"
|
||||||
|
MENTOR_VV = "MentorVV"
|
||||||
|
MENTOR_UK = "MentorUK"
|
||||||
|
SUPERVISOR = "Supervisor"
|
||||||
|
TRAINER = "Trainer"
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class CourseSessionWithRoles:
|
class CourseSessionWithRoles:
|
||||||
_original: CourseSession
|
_original: CourseSession
|
||||||
|
|
@ -28,7 +45,7 @@ class CourseSessionWithRoles:
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class CourseConfig:
|
class CourseConfig:
|
||||||
course_id: int
|
course_id: str
|
||||||
course_slug: str
|
course_slug: str
|
||||||
course_title: str
|
course_title: str
|
||||||
role_key: str
|
role_key: str
|
||||||
|
|
@ -289,7 +306,7 @@ def get_course_config(
|
||||||
session_to_continue = get_newest_cs(cs_in_course)
|
session_to_continue = get_newest_cs(cs_in_course)
|
||||||
course_configs.append(
|
course_configs.append(
|
||||||
CourseConfig(
|
CourseConfig(
|
||||||
course_id=cs_in_course[0].course.id,
|
course_id=str(cs_in_course[0].course.id),
|
||||||
course_slug=cs_in_course[0].course.slug,
|
course_slug=cs_in_course[0].course.slug,
|
||||||
course_title=cs_in_course[0].course.title,
|
course_title=cs_in_course[0].course.title,
|
||||||
role_key=role_key.value,
|
role_key=role_key.value,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue