Refactor `CourseCompletion` model
This commit is contained in:
parent
ab8dbd09ef
commit
3bd489d2ae
|
|
@ -19,10 +19,10 @@ const props = withDefaults(defineProps<Props>(), {
|
|||
<div class="flex flex-row items-center">
|
||||
<div v-if="showState" class="mr-4 h-8 w-8">
|
||||
<it-icon-smiley-happy
|
||||
v-if="criteria.completion_status === 'success'"
|
||||
v-if="criteria.completion_status === 'SUCCESS'"
|
||||
></it-icon-smiley-happy>
|
||||
<it-icon-smiley-thinking
|
||||
v-else-if="criteria.completion_status === 'fail'"
|
||||
v-else-if="criteria.completion_status === 'FAIL'"
|
||||
></it-icon-smiley-thinking>
|
||||
<it-icon-smiley-neutral v-else></it-icon-smiley-neutral>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
|
||||
export type StatusCountKey = "fail" | "success" | "unknown";
|
||||
export type StatusCountKey = "FAIL" | "SUCCESS" | "UNKNOWN";
|
||||
export type StatusCount = Record<StatusCountKey, number>;
|
||||
|
||||
const props = defineProps<{
|
||||
|
|
@ -10,9 +10,9 @@ const props = defineProps<{
|
|||
|
||||
const total = computed(() => {
|
||||
return (
|
||||
(props.statusCount?.fail || 0) +
|
||||
(props.statusCount?.success || 0) +
|
||||
(props.statusCount?.unknown || 0)
|
||||
(props.statusCount?.FAIL || 0) +
|
||||
(props.statusCount?.SUCCESS || 0) +
|
||||
(props.statusCount?.UNKNOWN || 0)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ const done = computed(() => {
|
|||
return 0;
|
||||
}
|
||||
|
||||
return ((props.statusCount?.success || 0) / total.value) * 100;
|
||||
return ((props.statusCount?.SUCCESS || 0) / total.value) * 100;
|
||||
});
|
||||
|
||||
const notDone = computed(() => {
|
||||
|
|
@ -29,7 +29,7 @@ const notDone = computed(() => {
|
|||
return 0;
|
||||
}
|
||||
|
||||
return ((props.statusCount?.fail || 0) / total.value) * 100 + done.value;
|
||||
return ((props.statusCount?.FAIL || 0) / total.value) * 100 + done.value;
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { CourseCompletionStatus } from "@/types";
|
||||
|
||||
export const COMPLETION_SUCCESS: CourseCompletionStatus = "success";
|
||||
export const COMPLETION_FAILURE: CourseCompletionStatus = "fail";
|
||||
export const COMPLETION_UNKNOWN: CourseCompletionStatus = "unknown";
|
||||
export const COMPLETION_SUCCESS: CourseCompletionStatus = "SUCCESS";
|
||||
export const COMPLETION_FAILURE: CourseCompletionStatus = "FAIL";
|
||||
export const COMPLETION_UNKNOWN: CourseCompletionStatus = "UNKNOWN";
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ const assignmentDetail = computed(() =>
|
|||
</template>
|
||||
<template #link>
|
||||
<router-link
|
||||
v-if="submissionStatusForUser(csu.user_id)?.progressStatus === 'success'"
|
||||
v-if="submissionStatusForUser(csu.user_id)?.progressStatus === 'SUCCESS'"
|
||||
:to="`/course/${props.courseSession.course.slug}/cockpit/assignment/${assignment.assignmentId}/${csu.user_id}`"
|
||||
class="w-full text-right underline"
|
||||
data-cy="show-results"
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ onMounted(async () => {
|
|||
</div>
|
||||
<div><ItProgress :status-count="state.progressStatusCount" /></div>
|
||||
<div class="text-gray-900" :class="{ 'text-gray-900': showTitle }">
|
||||
{{ state.progressStatusCount.success || 0 }} von
|
||||
{{ state.progressStatusCount.SUCCESS || 0 }} von
|
||||
{{
|
||||
(state.progressStatusCount.success || 0) +
|
||||
(state.progressStatusCount.unknown || 0)
|
||||
(state.progressStatusCount.SUCCESS || 0) +
|
||||
(state.progressStatusCount.UNKNOWN || 0)
|
||||
}}
|
||||
Lernenden haben ihre Ergebnisse eingereicht.
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ function setActiveClasses(translationKey: string) {
|
|||
class="mr-2 inline-block h-8 w-8"
|
||||
></it-icon-smiley-thinking>
|
||||
<p class="text-bold inline-block">
|
||||
{{ userCountStatusForCircle(csu.user_id, circle).fail }}
|
||||
{{ userCountStatusForCircle(csu.user_id, circle).FAIL }}
|
||||
</p>
|
||||
</div>
|
||||
<li class="mr-6 flex flex-row items-center">
|
||||
|
|
@ -182,7 +182,7 @@ function setActiveClasses(translationKey: string) {
|
|||
class="mr-2 inline-block h-8 w-8"
|
||||
></it-icon-smiley-happy>
|
||||
<p class="text-bold inline-block">
|
||||
{{ userCountStatusForCircle(csu.user_id, circle).success }}
|
||||
{{ userCountStatusForCircle(csu.user_id, circle).SUCCESS }}
|
||||
</p>
|
||||
</li>
|
||||
<li class="flex flex-row items-center">
|
||||
|
|
@ -190,7 +190,7 @@ function setActiveClasses(translationKey: string) {
|
|||
class="mr-2 inline-block h-8 w-8"
|
||||
></it-icon-smiley-neutral>
|
||||
<p class="text-bold inline-block">
|
||||
{{ userCountStatusForCircle(csu.user_id, circle).unknown }}
|
||||
{{ userCountStatusForCircle(csu.user_id, circle).UNKNOWN }}
|
||||
</p>
|
||||
</li>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const failedCriteria = computed(() => {
|
|||
return competenceStore
|
||||
.flatPerformanceCriteria()
|
||||
.filter((criteria) => {
|
||||
return criteria.completion_status === "fail";
|
||||
return criteria.completion_status === "FAIL";
|
||||
})
|
||||
.slice(0, 3);
|
||||
});
|
||||
|
|
@ -111,7 +111,7 @@ const countStatus = computed(() => {
|
|||
<h5 class="mb-4 text-gray-700">«{{ $t("selfEvaluation.no") }}»</h5>
|
||||
<div class="flex flex-row items-center">
|
||||
<it-icon-smiley-thinking class="h-16 w-16"></it-icon-smiley-thinking>
|
||||
<p class="ml-4 inline-block text-7xl font-bold">{{ countStatus.fail }}</p>
|
||||
<p class="ml-4 inline-block text-7xl font-bold">{{ countStatus.FAIL }}</p>
|
||||
</div>
|
||||
</li>
|
||||
<li
|
||||
|
|
@ -121,7 +121,7 @@ const countStatus = computed(() => {
|
|||
<div class="flex flex-row items-center">
|
||||
<it-icon-smiley-happy class="h-16 w-16"></it-icon-smiley-happy>
|
||||
<p class="ml-4 inline-block text-7xl font-bold">
|
||||
{{ countStatus.success }}
|
||||
{{ countStatus.SUCCESS }}
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
|
|
@ -130,7 +130,7 @@ const countStatus = computed(() => {
|
|||
<div class="flex flex-row items-center">
|
||||
<it-icon-smiley-neutral class="h-16 w-16"></it-icon-smiley-neutral>
|
||||
<p class="ml-4 inline-block text-7xl font-bold">
|
||||
{{ countStatus.unknown }}
|
||||
{{ countStatus.UNKNOWN }}
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -32,17 +32,17 @@ const { t } = useTranslation();
|
|||
|
||||
const mobileMenuItems: MenuItem[] = [
|
||||
{
|
||||
id: "fail",
|
||||
id: "FAIL",
|
||||
name: `«${t("selfEvaluation.no")}»`,
|
||||
iconName: "it-icon-smiley-thinking",
|
||||
},
|
||||
{
|
||||
id: "success",
|
||||
id: "SUCCESS",
|
||||
name: `«${t("selfEvaluation.yes")}»`,
|
||||
iconName: "it-icon-smiley-happy",
|
||||
},
|
||||
{
|
||||
id: "unknown",
|
||||
id: "UNKNOWN",
|
||||
name: t("competences.notAssessed"),
|
||||
iconName: "it-icon-smiley-neutral",
|
||||
},
|
||||
|
|
@ -91,7 +91,7 @@ function updateActiveState(status: CourseCompletionStatus) {
|
|||
:key="item.id"
|
||||
:class="{
|
||||
'bg-gray-200': activeMenuItem.id === item.id,
|
||||
'mr-6': item.id !== 'unknown',
|
||||
'mr-6': item.id !== 'UNKNOWN',
|
||||
}"
|
||||
class="mr-6 inline-block px-2 py-4"
|
||||
@click="updateActiveState(item.id)"
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ const singleCriteria = computed(() => {
|
|||
<button
|
||||
class="inline-flex flex-1 items-center border p-4 text-left"
|
||||
:class="{
|
||||
'border-green-500': singleCriteria.completion_status === 'success',
|
||||
'border-2': singleCriteria.completion_status === 'success',
|
||||
'border-green-500': singleCriteria.completion_status === 'SUCCESS',
|
||||
'border-2': singleCriteria.completion_status === 'SUCCESS',
|
||||
}"
|
||||
data-cy="success"
|
||||
@click="circleStore.markCompletion(singleCriteria, 'success')"
|
||||
@click="circleStore.markCompletion(singleCriteria, 'SUCCESS')"
|
||||
>
|
||||
<it-icon-smiley-happy class="mr-4 h-16 w-16"></it-icon-smiley-happy>
|
||||
<span class="text-large font-bold">{{ $t("selfEvaluation.yes") }}</span>
|
||||
|
|
@ -51,11 +51,11 @@ const singleCriteria = computed(() => {
|
|||
<button
|
||||
class="inline-flex flex-1 items-center border p-4 text-left"
|
||||
:class="{
|
||||
'border-orange-500': singleCriteria.completion_status === 'fail',
|
||||
'border-2': singleCriteria.completion_status === 'fail',
|
||||
'border-orange-500': singleCriteria.completion_status === 'FAIL',
|
||||
'border-2': singleCriteria.completion_status === 'FAIL',
|
||||
}"
|
||||
data-cy="fail"
|
||||
@click="circleStore.markCompletion(singleCriteria, 'fail')"
|
||||
@click="circleStore.markCompletion(singleCriteria, 'FAIL')"
|
||||
>
|
||||
<it-icon-smiley-thinking class="mr-4 h-16 w-16"></it-icon-smiley-thinking>
|
||||
<span class="text-xl font-bold">{{ $t("selfEvaluation.no") }}</span>
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ const props = withDefaults(defineProps<Props>(), {
|
|||
const circleStore = useCircleStore();
|
||||
|
||||
function toggleCompleted(learningContent: LearningContentInterface) {
|
||||
let completionStatus: CourseCompletionStatus = "success";
|
||||
if (learningContent.completion_status === "success") {
|
||||
completionStatus = "fail";
|
||||
let completionStatus: CourseCompletionStatus = "SUCCESS";
|
||||
if (learningContent.completion_status === "SUCCESS") {
|
||||
completionStatus = "FAIL";
|
||||
}
|
||||
circleStore.markCompletion(learningContent, completionStatus);
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ const continueTranslationKeyTuple = computed(() => {
|
|||
const lastFinished = findLast(
|
||||
circleStore.circle.flatLearningContents,
|
||||
(learningContent) => {
|
||||
return learningContent.completion_status === "success";
|
||||
return learningContent.completion_status === "SUCCESS";
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ const learningSequenceBorderClass = computed(() => {
|
|||
>
|
||||
<div v-if="props.readonly">
|
||||
<it-icon-check
|
||||
v-if="learningContent.completion_status === 'success'"
|
||||
v-if="learningContent.completion_status === 'SUCCESS'"
|
||||
class="block h-8 w-8"
|
||||
></it-icon-check>
|
||||
<div v-else class="h-8 w-8"></div>
|
||||
|
|
@ -136,7 +136,7 @@ const learningSequenceBorderClass = computed(() => {
|
|||
v-else
|
||||
:checkbox-item="{
|
||||
value: learningContent.completion_status,
|
||||
checked: learningContent.completion_status === 'success',
|
||||
checked: learningContent.completion_status === 'SUCCESS',
|
||||
}"
|
||||
:data-cy="`${learningContent.slug}-checkbox`"
|
||||
@toggle="toggleCompleted(learningContent)"
|
||||
|
|
@ -194,14 +194,14 @@ const learningSequenceBorderClass = computed(() => {
|
|||
@click="!props.readonly && circleStore.openSelfEvaluation(learningUnit)"
|
||||
>
|
||||
<div
|
||||
v-if="circleStore.calcSelfEvaluationStatus(learningUnit) === 'success'"
|
||||
v-if="circleStore.calcSelfEvaluationStatus(learningUnit) === 'SUCCESS'"
|
||||
class="self-evaluation-success flex items-center gap-4 pb-3 lg:pb-6"
|
||||
>
|
||||
<it-icon-smiley-happy class="h-8 w-8 flex-none" data-cy="success" />
|
||||
<div>{{ $t("selfEvaluation.selfEvaluationYes") }}</div>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="circleStore.calcSelfEvaluationStatus(learningUnit) === 'fail'"
|
||||
v-else-if="circleStore.calcSelfEvaluationStatus(learningUnit) === 'FAIL'"
|
||||
class="self-evaluation-fail flex items-center gap-4 pb-3 lg:pb-6"
|
||||
>
|
||||
<it-icon-smiley-thinking class="h-8 w-8 flex-none" data-cy="fail" />
|
||||
|
|
|
|||
|
|
@ -93,8 +93,8 @@ onUnmounted(() => {
|
|||
<button
|
||||
class="inline-flex flex-1 items-center border p-4 text-left"
|
||||
:class="{
|
||||
'border-green-500': currentQuestion.completion_status === 'success',
|
||||
'border-2': currentQuestion.completion_status === 'success',
|
||||
'border-green-500': currentQuestion.completion_status === 'SUCCESS',
|
||||
'border-2': currentQuestion.completion_status === 'SUCCESS',
|
||||
}"
|
||||
data-cy="success"
|
||||
@click="circleStore.markCompletion(currentQuestion, COMPLETION_SUCCESS)"
|
||||
|
|
@ -112,7 +112,7 @@ onUnmounted(() => {
|
|||
'border-2': currentQuestion.completion_status === COMPLETION_FAILURE,
|
||||
}"
|
||||
data-cy="fail"
|
||||
@click="circleStore.markCompletion(currentQuestion, 'fail')"
|
||||
@click="circleStore.markCompletion(currentQuestion, 'FAIL')"
|
||||
>
|
||||
<it-icon-smiley-thinking
|
||||
class="mr-4 h-16 w-16"
|
||||
|
|
|
|||
|
|
@ -70,13 +70,13 @@ export function calcUserAssignmentCompletionStatus(
|
|||
if (userAssignmentStatus) {
|
||||
userStatus = userAssignmentStatus.completion_status;
|
||||
}
|
||||
let progressStatus: StatusCountKey = "unknown";
|
||||
let progressStatus: StatusCountKey = "UNKNOWN";
|
||||
if (
|
||||
["SUBMITTED", "EVALUATION_IN_PROGRESS", "EVALUATION_SUBMITTED"].includes(
|
||||
userStatus
|
||||
)
|
||||
) {
|
||||
progressStatus = "success";
|
||||
progressStatus = "SUCCESS";
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ export class Circle implements WagtailCircle {
|
|||
return (
|
||||
this.flatChildren.filter((lc) => {
|
||||
return (
|
||||
lc.completion_status === "success" &&
|
||||
lc.completion_status === "SUCCESS" &&
|
||||
lc.parentLearningSequence?.translation_key === translationKey
|
||||
);
|
||||
}).length > 0
|
||||
|
|
@ -229,12 +229,12 @@ export class Circle implements WagtailCircle {
|
|||
);
|
||||
|
||||
return (
|
||||
learningContents.every((lc) => lc.completion_status === "success") &&
|
||||
learningContents.every((lc) => lc.completion_status === "SUCCESS") &&
|
||||
(groupedPerformanceCriteria.length === 0 ||
|
||||
groupedPerformanceCriteria.every((group) =>
|
||||
group.every(
|
||||
(pc) =>
|
||||
pc.completion_status === "success" || pc.completion_status === "fail"
|
||||
pc.completion_status === "SUCCESS" || pc.completion_status === "FAIL"
|
||||
)
|
||||
))
|
||||
);
|
||||
|
|
@ -252,12 +252,12 @@ export class Circle implements WagtailCircle {
|
|||
public parseCompletionData(completionData: CourseCompletion[]) {
|
||||
this.flatChildren.forEach((page) => {
|
||||
const pageIndex = completionData.findIndex((e) => {
|
||||
return e.page_key === page.translation_key;
|
||||
return e.page_id === page.id;
|
||||
});
|
||||
if (pageIndex >= 0) {
|
||||
page.completion_status = completionData[pageIndex].completion_status;
|
||||
} else {
|
||||
page.completion_status = "unknown";
|
||||
page.completion_status = "UNKNOWN";
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ function getLastCompleted(courseSlug: string, completionData: CourseCompletion[]
|
|||
const courseSession = courseSessionsStore.courseSessionForCourse(courseSlug);
|
||||
return orderBy(completionData, ["updated_at"], "desc").find((c: CourseCompletion) => {
|
||||
return (
|
||||
c.completion_status === "success" &&
|
||||
c.completion_status === "SUCCESS" &&
|
||||
c.course_session === courseSession?.id &&
|
||||
c.page_type.startsWith("learnpath.LearningContent")
|
||||
);
|
||||
|
|
@ -129,13 +129,13 @@ export class LearningPath implements WagtailLearningPath {
|
|||
const lastCircle = this.circles.find((circle) => {
|
||||
return circle.flatLearningContents.find(
|
||||
(learningContent) =>
|
||||
learningContent.translation_key === lastCompletedLearningContent.page_key
|
||||
learningContent.id === lastCompletedLearningContent.page_id
|
||||
);
|
||||
});
|
||||
if (lastCircle) {
|
||||
const lastLearningContent = lastCircle.flatLearningContents.find(
|
||||
(learningContent) =>
|
||||
learningContent.translation_key === lastCompletedLearningContent.page_key
|
||||
learningContent.id === lastCompletedLearningContent.page_id
|
||||
);
|
||||
if (lastLearningContent && lastLearningContent.nextLearningContent) {
|
||||
this.nextLearningContent = lastLearningContent.nextLearningContent;
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ export const useCircleStore = defineStore({
|
|||
| LearningUnitPerformanceCriteria
|
||||
| PerformanceCriteria
|
||||
| undefined,
|
||||
completion_status: CourseCompletionStatus = "success"
|
||||
completion_status: CourseCompletionStatus = "SUCCESS"
|
||||
) {
|
||||
const completionStore = useCompletionStore();
|
||||
|
||||
|
|
@ -146,22 +146,22 @@ export const useCircleStore = defineStore({
|
|||
},
|
||||
calcSelfEvaluationStatus(learningUnit: LearningUnit): CourseCompletionStatus {
|
||||
if (learningUnit.children.length > 0) {
|
||||
if (learningUnit.children.every((q) => q.completion_status === "success")) {
|
||||
return "success";
|
||||
if (learningUnit.children.every((q) => q.completion_status === "SUCCESS")) {
|
||||
return "SUCCESS";
|
||||
}
|
||||
if (
|
||||
learningUnit.children.every(
|
||||
(q) => q.completion_status === "fail" || q.completion_status === "success"
|
||||
(q) => q.completion_status === "FAIL" || q.completion_status === "SUCCESS"
|
||||
)
|
||||
) {
|
||||
return "fail";
|
||||
return "FAIL";
|
||||
}
|
||||
}
|
||||
return "unknown";
|
||||
return "UNKNOWN";
|
||||
},
|
||||
continueFromLearningContent(currentLearningContent: LearningContentInterface) {
|
||||
if (currentLearningContent) {
|
||||
this.markCompletion(currentLearningContent, "success");
|
||||
this.markCompletion(currentLearningContent, "SUCCESS");
|
||||
this.closeLearningContent(currentLearningContent);
|
||||
} else {
|
||||
log.error("currentLearningContent is undefined");
|
||||
|
|
|
|||
|
|
@ -35,16 +35,16 @@ export const useCompetenceStore = defineStore({
|
|||
if (criteria) {
|
||||
const grouped = groupBy(criteria, "completion_status");
|
||||
return {
|
||||
fail: grouped?.fail?.length || 0,
|
||||
success: grouped?.success?.length || 0,
|
||||
unknown: grouped?.unknown?.length || 0,
|
||||
FAIL: grouped?.FAIL.length || 0,
|
||||
SUCCESS: grouped?.SUCCESS.length || 0,
|
||||
UNKNOWN: grouped?.UNKNOWN.length || 0,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: 0,
|
||||
fail: 0,
|
||||
unknown: 0,
|
||||
SUCCESS: 0,
|
||||
FAIL: 0,
|
||||
UNKNOWN: 0,
|
||||
};
|
||||
},
|
||||
criteriaByCompetence(competence: CompetencePage) {
|
||||
|
|
@ -177,14 +177,14 @@ export const useCompetenceStore = defineStore({
|
|||
competenceProfilePage.children.forEach((competence) => {
|
||||
competence.children.forEach((performanceCriteria) => {
|
||||
const completion = completionData.find(
|
||||
(c) => c.page_key === performanceCriteria.translation_key
|
||||
(c) => c.page_id === performanceCriteria.id
|
||||
);
|
||||
if (completion) {
|
||||
performanceCriteria.completion_status = completion.completion_status;
|
||||
performanceCriteria.completion_status_updated_at =
|
||||
completion.updated_at;
|
||||
} else {
|
||||
performanceCriteria.completion_status = "unknown";
|
||||
performanceCriteria.completion_status = "UNKNOWN";
|
||||
performanceCriteria.completion_status_updated_at = "";
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export const useCompletionStore = defineStore({
|
|||
|
||||
if (courseSessionId) {
|
||||
const completionData = await itPost("/api/course/completion/mark/", {
|
||||
page_key: page.translation_key,
|
||||
page_id: page.id,
|
||||
completion_status: page.completion_status,
|
||||
course_session_id: courseSessionId,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import type { Component } from "vue";
|
|||
|
||||
export type LoginMethod = "local" | "sso";
|
||||
|
||||
export type CourseCompletionStatus = "unknown" | "fail" | "success";
|
||||
export type CourseCompletionStatus = "UNKNOWN" | "FAIL" | "SUCCESS";
|
||||
|
||||
export interface BaseCourseWagtailPage {
|
||||
readonly id: number;
|
||||
|
|
@ -169,14 +169,13 @@ export interface Topic extends BaseCourseWagtailPage {
|
|||
export type LearningPathChild = Topic | WagtailCircle;
|
||||
|
||||
export interface CourseCompletion {
|
||||
id: number;
|
||||
readonly id: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
user: number;
|
||||
page_key: string;
|
||||
page_type: string;
|
||||
page_slug: string;
|
||||
course_session: number;
|
||||
readonly user: number;
|
||||
readonly page_id: number;
|
||||
readonly page_type: string;
|
||||
readonly course_session: number;
|
||||
completion_status: CourseCompletionStatus;
|
||||
additional_json_data: unknown;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -464,19 +464,19 @@ def create_course_uk_de_completion_data(course_session):
|
|||
for circle in circles:
|
||||
for index, lc in enumerate(circle.get_descendants().type(LearningContent)):
|
||||
mark_course_completion(
|
||||
str(lc.translation_key),
|
||||
User.objects.get(email="lina.egger@example.com"),
|
||||
page=lc,
|
||||
user=User.objects.get(email="lina.egger@example.com"),
|
||||
course_session=course_session,
|
||||
completion_status="success",
|
||||
completion_status="SUCCESS",
|
||||
)
|
||||
|
||||
random_number = random.randint(1, 3)
|
||||
if index % random_number == 0:
|
||||
mark_course_completion(
|
||||
str(lc.translation_key),
|
||||
User.objects.get(email="michael.meier@example.com"),
|
||||
page=lc,
|
||||
user=User.objects.get(email="michael.meier@example.com"),
|
||||
course_session=course_session,
|
||||
completion_status="success",
|
||||
completion_status="SUCCESS",
|
||||
)
|
||||
|
||||
performance_criteria = (
|
||||
|
|
@ -486,26 +486,26 @@ def create_course_uk_de_completion_data(course_session):
|
|||
)
|
||||
for index, pc in enumerate(performance_criteria):
|
||||
mark_course_completion(
|
||||
str(pc.translation_key),
|
||||
User.objects.get(email="lina.egger@example.com"),
|
||||
page=pc,
|
||||
user=User.objects.get(email="lina.egger@example.com"),
|
||||
course_session=course_session,
|
||||
completion_status="success",
|
||||
completion_status="SUCCESS",
|
||||
)
|
||||
|
||||
random_number = random.randint(1, 4)
|
||||
if index % random_number == 0:
|
||||
mark_course_completion(
|
||||
str(pc.translation_key),
|
||||
User.objects.get(email="michael.meier@example.com"),
|
||||
page=pc,
|
||||
user=User.objects.get(email="michael.meier@example.com"),
|
||||
course_session=course_session,
|
||||
completion_status="success",
|
||||
completion_status="SUCCESS",
|
||||
)
|
||||
if index % random_number == 1:
|
||||
mark_course_completion(
|
||||
str(pc.translation_key),
|
||||
User.objects.get(email="michael.meier@example.com"),
|
||||
page=pc,
|
||||
user=User.objects.get(email="michael.meier@example.com"),
|
||||
course_session=course_session,
|
||||
completion_status="fail",
|
||||
completion_status="FAIL",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
# Generated by Django 3.2.13 on 2023-06-26 15:24
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import vbv_lernwelt.course.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0083_workflowcontenttype'),
|
||||
('course', '0005_remove_coursesession_attendance_courses'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveConstraint(
|
||||
model_name='coursecompletion',
|
||||
name='course_completion_unique_user_page_key',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='coursecompletion',
|
||||
name='page_key',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='coursecompletion',
|
||||
name='page_slug',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='coursecompletion',
|
||||
name='page',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='wagtailcore.page'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='coursecompletion',
|
||||
name='completion_status',
|
||||
field=models.CharField(choices=[(vbv_lernwelt.course.models.CourseCompletionStatus['SUCCESS'], 'SUCCESS'), (vbv_lernwelt.course.models.CourseCompletionStatus['FAIL'], 'FAIL'), (vbv_lernwelt.course.models.CourseCompletionStatus['UNKNOWN'], 'UNKNOWN')], default='UNKNOWN', max_length=255),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='coursecompletion',
|
||||
constraint=models.UniqueConstraint(fields=('user', 'page', 'course_session'), name='course_completion_unique_user_page_key'),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
import enum
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import UniqueConstraint
|
||||
from django.utils.text import slugify
|
||||
|
|
@ -152,6 +154,12 @@ class CoursePage(CourseBasePage):
|
|||
return f"{self.title}"
|
||||
|
||||
|
||||
class CourseCompletionStatus(enum.Enum):
|
||||
SUCCESS = "SUCCESS"
|
||||
FAIL = "FAIL"
|
||||
UNKNOWN = "UNKNOWN"
|
||||
|
||||
|
||||
class CourseCompletion(models.Model):
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
|
@ -159,27 +167,24 @@ class CourseCompletion(models.Model):
|
|||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
|
||||
# page can logically be a LearningContent or a PerformanceCriteria for now
|
||||
page_key = models.UUIDField()
|
||||
page = models.ForeignKey(Page, on_delete=models.CASCADE)
|
||||
|
||||
# store for convenience and performance...
|
||||
page_type = models.CharField(max_length=255, default="", blank=True)
|
||||
page_slug = models.CharField(max_length=255, default="", blank=True)
|
||||
|
||||
course_session = models.ForeignKey("course.CourseSession", on_delete=models.CASCADE)
|
||||
|
||||
completion_status = models.CharField(
|
||||
max_length=255,
|
||||
choices=[
|
||||
("unknown", "unknown"),
|
||||
("success", "success"),
|
||||
("fail", "fail"),
|
||||
],
|
||||
default="unknown",
|
||||
choices=[(status, status.value) for status in CourseCompletionStatus],
|
||||
default=CourseCompletionStatus.UNKNOWN.value,
|
||||
)
|
||||
additional_json_data = models.JSONField(default=dict)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
UniqueConstraint(
|
||||
fields=["user", "page_key", "course_session"],
|
||||
fields=["user", "page", "course_session"],
|
||||
name="course_completion_unique_user_page_key",
|
||||
)
|
||||
]
|
||||
|
|
|
|||
|
|
@ -43,10 +43,9 @@ class CourseCompletionSerializer(serializers.ModelSerializer):
|
|||
"created_at",
|
||||
"updated_at",
|
||||
"user",
|
||||
"page_key",
|
||||
"page_id",
|
||||
"page_type",
|
||||
"page_slug",
|
||||
"course_session",
|
||||
"course_session_id",
|
||||
"completion_status",
|
||||
"additional_json_data",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,20 +1,23 @@
|
|||
from wagtail.models import Page
|
||||
|
||||
from vbv_lernwelt.course.models import CourseCompletion
|
||||
from vbv_lernwelt.course.models import CourseCompletion, CourseCompletionStatus
|
||||
from vbv_lernwelt.learnpath.utils import get_wagtail_type
|
||||
|
||||
|
||||
def mark_course_completion(page_key, user, course_session, completion_status="success"):
|
||||
page = Page.objects.get(translation_key=page_key, locale__language_code="de-CH")
|
||||
page_type = get_wagtail_type(page.specific)
|
||||
course = page.specific.get_course()
|
||||
def mark_course_completion(
|
||||
page, user, course_session, completion_status=CourseCompletionStatus.SUCCESS.value
|
||||
):
|
||||
if completion_status not in CourseCompletionStatus.__members__:
|
||||
raise ValueError(
|
||||
f"Invalid value for CourseCompletionStatus: {completion_status}"
|
||||
)
|
||||
|
||||
# TODO: check if this page can be "marked" by user
|
||||
cc, created = CourseCompletion.objects.get_or_create(
|
||||
user=user,
|
||||
page_key=page_key,
|
||||
user_id=user.id,
|
||||
page_id=page.id,
|
||||
course_session_id=course_session.id,
|
||||
)
|
||||
cc.page_slug = page.slug
|
||||
cc.page_type = page_type
|
||||
cc.completion_status = completion_status
|
||||
cc.page_type = get_wagtail_type(page.specific)
|
||||
|
||||
cc.save()
|
||||
return cc
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class CourseCompletionApiTestCase(APITestCase):
|
|||
def setUp(self) -> None:
|
||||
create_default_users()
|
||||
create_test_course(include_uk=False)
|
||||
self.user = User.objects.get(username="admin")
|
||||
self.user = User.objects.get(username="test-student1@example.com")
|
||||
self.cs = CourseSession.objects.create(
|
||||
course_id=COURSE_TEST_ID,
|
||||
title="Test Lehrgang Session",
|
||||
|
|
@ -27,20 +27,19 @@ class CourseCompletionApiTestCase(APITestCase):
|
|||
course_session=self.cs,
|
||||
user=self.user,
|
||||
)
|
||||
self.client.login(username="admin", password="test")
|
||||
self.client.force_login(self.user)
|
||||
|
||||
def test_completeLearningContent_works(self):
|
||||
def test_completeLearningContent_happyCase(self):
|
||||
learning_content = LearningContentPlaceholder.objects.get(
|
||||
title="Fachcheck Reisen"
|
||||
)
|
||||
learning_content_key = str(learning_content.translation_key)
|
||||
|
||||
mark_url = f"/api/course/completion/mark/"
|
||||
|
||||
response = self.client.post(
|
||||
mark_url,
|
||||
{
|
||||
"page_key": learning_content_key,
|
||||
"page_id": learning_content.id,
|
||||
"course_session_id": self.cs.id,
|
||||
},
|
||||
)
|
||||
|
|
@ -49,13 +48,16 @@ class CourseCompletionApiTestCase(APITestCase):
|
|||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(len(response_json), 1)
|
||||
self.assertEqual(response_json[0]["page_key"], learning_content_key)
|
||||
self.assertEqual(response_json[0]["completion_status"], "success")
|
||||
self.assertEqual(response_json[0]["page_id"], learning_content.id)
|
||||
self.assertEqual(
|
||||
response_json[0]["page_type"], "learnpath.LearningContentPlaceholder"
|
||||
)
|
||||
self.assertEqual(response_json[0]["completion_status"], "SUCCESS")
|
||||
|
||||
db_entry = CourseCompletion.objects.get(
|
||||
user=self.user, course_session_id=self.cs.id, page_key=learning_content_key
|
||||
user=self.user, course_session_id=self.cs.id, page_id=learning_content.id
|
||||
)
|
||||
self.assertEqual(db_entry.completion_status, "success")
|
||||
self.assertEqual(db_entry.completion_status, "SUCCESS")
|
||||
|
||||
# test getting the circle data
|
||||
response = self.client.get(f"/api/course/completion/{self.cs.id}/")
|
||||
|
|
@ -65,15 +67,18 @@ class CourseCompletionApiTestCase(APITestCase):
|
|||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(len(response_json), 1)
|
||||
self.assertEqual(response_json[0]["page_key"], learning_content_key)
|
||||
self.assertTrue(response_json[0]["completion_status"], "success")
|
||||
self.assertEqual(response_json[0]["page_id"], learning_content.id)
|
||||
self.assertEqual(
|
||||
response_json[0]["page_type"], "learnpath.LearningContentPlaceholder"
|
||||
)
|
||||
self.assertEqual(response_json[0]["completion_status"], "SUCCESS")
|
||||
|
||||
# test with "fail"
|
||||
response = self.client.post(
|
||||
mark_url,
|
||||
{
|
||||
"page_key": learning_content_key,
|
||||
"completion_status": "fail",
|
||||
"page_id": learning_content.id,
|
||||
"completion_status": "FAIL",
|
||||
"course_session_id": self.cs.id,
|
||||
},
|
||||
)
|
||||
|
|
@ -81,10 +86,13 @@ class CourseCompletionApiTestCase(APITestCase):
|
|||
response_json = response.json()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(len(response_json), 1)
|
||||
self.assertEqual(response_json[0]["page_key"], learning_content_key)
|
||||
self.assertEqual(response_json[0]["completion_status"], "fail")
|
||||
self.assertEqual(response_json[0]["page_id"], learning_content.id)
|
||||
self.assertEqual(
|
||||
response_json[0]["page_type"], "learnpath.LearningContentPlaceholder"
|
||||
)
|
||||
self.assertEqual(response_json[0]["completion_status"], "FAIL")
|
||||
|
||||
db_entry = CourseCompletion.objects.get(
|
||||
user=self.user, course_session_id=self.cs.id, page_key=learning_content_key
|
||||
user=self.user, course_session_id=self.cs.id, page_id=learning_content.id
|
||||
)
|
||||
self.assertEqual(db_entry.completion_status, "fail")
|
||||
self.assertEqual(db_entry.completion_status, "FAIL")
|
||||
|
|
|
|||
|
|
@ -89,20 +89,17 @@ def request_course_completion_for_user(request, course_session_id, user_id):
|
|||
@api_view(["POST"])
|
||||
def mark_course_completion_view(request):
|
||||
try:
|
||||
page_key = request.data.get("page_key")
|
||||
completion_status = request.data.get("completion_status", "success")
|
||||
page_id = request.data.get("page_id")
|
||||
completion_status = request.data.get("completion_status", "SUCCESS")
|
||||
course_session_id = request.data.get("course_session_id")
|
||||
page = Page.objects.get(translation_key=page_key, locale__language_code="de-CH")
|
||||
page = Page.objects.get(id=page_id)
|
||||
|
||||
if not has_course_access_by_page_request(request, page):
|
||||
raise PermissionDenied()
|
||||
|
||||
page_type = get_wagtail_type(page.specific)
|
||||
course = page.specific.get_course()
|
||||
|
||||
mark_course_completion(
|
||||
page_key,
|
||||
request.user,
|
||||
page=page,
|
||||
user=request.user,
|
||||
course_session=CourseSession.objects.get(id=course_session_id),
|
||||
completion_status=completion_status,
|
||||
)
|
||||
|
|
@ -117,8 +114,8 @@ def mark_course_completion_view(request):
|
|||
logger.debug(
|
||||
"mark_course_completion successful",
|
||||
label="completion_api",
|
||||
page_key=page_key,
|
||||
page_type=page_type,
|
||||
page_id=page_id,
|
||||
page_type=get_wagtail_type(page.specific),
|
||||
page_slug=page.slug,
|
||||
page_title=page.title,
|
||||
user_id=request.user.id,
|
||||
|
|
|
|||
|
|
@ -38,12 +38,12 @@ def update_attendance_list(
|
|||
}
|
||||
)
|
||||
completion_status = (
|
||||
"success"
|
||||
"SUCCESS"
|
||||
if attendance_user.get("status").value == "PRESENT"
|
||||
else "fail"
|
||||
else "FAIL"
|
||||
)
|
||||
mark_course_completion(
|
||||
page_key=attendance_course.learning_content.translation_key,
|
||||
page=attendance_course.learning_content,
|
||||
user=u,
|
||||
course_session=attendance_course.course_session,
|
||||
completion_status=completion_status,
|
||||
|
|
@ -63,10 +63,10 @@ def update_attendance_list(
|
|||
u = User.objects.filter(id=user_id).first()
|
||||
if u is not None:
|
||||
mark_course_completion(
|
||||
page_key=attendance_course.learning_content.translation_key,
|
||||
page=attendance_course.learning_content,
|
||||
user=u,
|
||||
course_session=attendance_course.course_session,
|
||||
completion_status="fail",
|
||||
completion_status="FAIL",
|
||||
)
|
||||
|
||||
return attendance_course
|
||||
|
|
|
|||
|
|
@ -59,13 +59,8 @@ class AttendanceServicesTestCase(TestCase):
|
|||
self.assertEqual(CourseCompletion.objects.count(), 1)
|
||||
cc = CourseCompletion.objects.first()
|
||||
self.assertEqual(cc.user, student)
|
||||
self.assertEqual(cc.completion_status, "success")
|
||||
self.assertEqual(
|
||||
cc.page_key, self.attendance_course.learning_content.translation_key
|
||||
)
|
||||
self.assertEqual(
|
||||
cc.page_slug, "test-lehrgang-lp-circle-fahrzeug-lc-präsenzkurs-fahrzeug"
|
||||
)
|
||||
self.assertEqual(cc.completion_status, "SUCCESS")
|
||||
self.assertEqual(cc.page_id, self.attendance_course.learning_content.id)
|
||||
|
||||
def test_updateAttendanceList_withRemovedUser_willUpdateUserCourseCompletion(self):
|
||||
student = User.objects.get(username="test-student1@example.com")
|
||||
|
|
@ -80,20 +75,15 @@ class AttendanceServicesTestCase(TestCase):
|
|||
]
|
||||
self.attendance_course.save()
|
||||
mark_course_completion(
|
||||
page_key=self.attendance_course.learning_content.translation_key,
|
||||
page=self.attendance_course.learning_content,
|
||||
user=student,
|
||||
course_session=self.course_session,
|
||||
completion_status="success",
|
||||
completion_status="SUCCESS",
|
||||
)
|
||||
update_attendance_list(self.attendance_course, [])
|
||||
|
||||
self.assertEqual(CourseCompletion.objects.count(), 1)
|
||||
cc = CourseCompletion.objects.first()
|
||||
self.assertEqual(cc.user, student)
|
||||
self.assertEqual(cc.completion_status, "fail")
|
||||
self.assertEqual(
|
||||
cc.page_key, self.attendance_course.learning_content.translation_key
|
||||
)
|
||||
self.assertEqual(
|
||||
cc.page_slug, "test-lehrgang-lp-circle-fahrzeug-lc-präsenzkurs-fahrzeug"
|
||||
)
|
||||
self.assertEqual(cc.completion_status, "FAIL")
|
||||
self.assertEqual(cc.page_id, self.attendance_course.learning_content.id)
|
||||
|
|
|
|||
Loading…
Reference in New Issue