Mark LearningContentAssignment completion in backend

This commit is contained in:
Daniel Egger 2023-06-26 18:44:44 +02:00
parent 36152a4364
commit 3d4654efbc
5 changed files with 81 additions and 24 deletions

View File

@ -4,9 +4,11 @@ import ItButton from "@/components/ui/ItButton.vue";
import ItCheckbox from "@/components/ui/ItCheckbox.vue"; import ItCheckbox from "@/components/ui/ItCheckbox.vue";
import ItSuccessAlert from "@/components/ui/ItSuccessAlert.vue"; import ItSuccessAlert from "@/components/ui/ItSuccessAlert.vue";
import { useCurrentCourseSession } from "@/composables"; import { useCurrentCourseSession } from "@/composables";
import { bustItGetCache } from "@/fetchHelpers";
import { UPSERT_ASSIGNMENT_COMPLETION_MUTATION } from "@/graphql/mutations"; import { UPSERT_ASSIGNMENT_COMPLETION_MUTATION } from "@/graphql/mutations";
import AssignmentSubmissionResponses from "@/pages/learningPath/learningContentPage/assignment/AssignmentSubmissionResponses.vue"; import AssignmentSubmissionResponses from "@/pages/learningPath/learningContentPage/assignment/AssignmentSubmissionResponses.vue";
import { useCourseSessionsStore } from "@/stores/courseSessions"; import { useCourseSessionsStore } from "@/stores/courseSessions";
import { useUserStore } from "@/stores/user";
import type { Assignment, AssignmentCompletion, AssignmentTask } from "@/types"; import type { Assignment, AssignmentCompletion, AssignmentTask } from "@/types";
import { useMutation } from "@urql/vue"; import { useMutation } from "@urql/vue";
import type { Dayjs } from "dayjs"; import type { Dayjs } from "dayjs";
@ -61,7 +63,7 @@ const onEditTask = (task: AssignmentTask) => {
const onSubmit = async () => { const onSubmit = async () => {
try { try {
// noinspection TypeScriptValidateTypes // noinspection TypeScriptValidateTypes
upsertAssignmentCompletionMutation.executeMutation({ await upsertAssignmentCompletionMutation.executeMutation({
assignmentId: props.assignment.id.toString(), assignmentId: props.assignment.id.toString(),
courseSessionId: courseSession.value.id.toString(), courseSessionId: courseSession.value.id.toString(),
completionDataString: JSON.stringify({}), completionDataString: JSON.stringify({}),
@ -70,6 +72,9 @@ const onSubmit = async () => {
// @ts-ignore // @ts-ignore
id: props.assignmentCompletion?.id, id: props.assignmentCompletion?.id,
}); });
bustItGetCache(
`/api/course/completion/${courseSession.value.id}/${useUserStore().id}/`
);
} catch (error) { } catch (error) {
log.error("Could not submit assignment", error); log.error("Could not submit assignment", error);
} }

View File

@ -163,6 +163,9 @@ export const useCircleStore = defineStore({
if (currentLearningContent) { if (currentLearningContent) {
if (currentLearningContent.can_user_self_toggle_course_completion) { if (currentLearningContent.can_user_self_toggle_course_completion) {
this.markCompletion(currentLearningContent, "SUCCESS"); this.markCompletion(currentLearningContent, "SUCCESS");
} else {
// reload completion data anyway
currentLearningContent.parentCircle?.parentLearningPath?.reloadCompletionData();
} }
this.closeLearningContent(currentLearningContent); this.closeLearningContent(currentLearningContent);
} else { } else {

View File

@ -12,7 +12,8 @@ from vbv_lernwelt.assignment.models import (
) )
from vbv_lernwelt.core.models import User from vbv_lernwelt.core.models import User
from vbv_lernwelt.core.utils import find_first from vbv_lernwelt.core.utils import find_first
from vbv_lernwelt.course.models import CourseSession from vbv_lernwelt.course.models import CourseCompletionStatus, CourseSession
from vbv_lernwelt.course.services import mark_course_completion
def update_assignment_completion( def update_assignment_completion(
@ -172,11 +173,15 @@ def update_assignment_completion(
acl.completion_data[key].update(task_data) acl.completion_data[key].update(task_data)
acl.save() acl.save()
# if completion_status == "SUBMITTED": if completion_status == "SUBMITTED":
# mark_course_completion( learning_content = assignment.learningcontentassignment_set.first()
# user=assignment_user, if learning_content:
# page=ac. mark_course_completion(
# ) user=assignment_user,
page=learning_content,
course_session=course_session,
completion_status=CourseCompletionStatus.SUCCESS.value,
)
return ac return ac

View File

@ -1,43 +1,65 @@
# Generated by Django 3.2.13 on 2023-06-26 15:24 # Generated by Django 3.2.13 on 2023-06-26 15:24
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
import vbv_lernwelt.course.models import vbv_lernwelt.course.models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('wagtailcore', '0083_workflowcontenttype'), ("wagtailcore", "0083_workflowcontenttype"),
('course', '0005_remove_coursesession_attendance_courses'), ("course", "0005_remove_coursesession_attendance_courses"),
] ]
operations = [ operations = [
migrations.RemoveConstraint( migrations.RemoveConstraint(
model_name='coursecompletion', model_name="coursecompletion",
name='course_completion_unique_user_page_key', name="course_completion_unique_user_page_key",
), ),
migrations.RemoveField( migrations.RemoveField(
model_name='coursecompletion', model_name="coursecompletion",
name='page_key', name="page_key",
), ),
migrations.RemoveField( migrations.RemoveField(
model_name='coursecompletion', model_name="coursecompletion",
name='page_slug', name="page_slug",
), ),
migrations.AddField( migrations.AddField(
model_name='coursecompletion', model_name="coursecompletion",
name='page', name="page",
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='wagtailcore.page'), field=models.ForeignKey(
default=1,
on_delete=django.db.models.deletion.CASCADE,
to="wagtailcore.page",
),
preserve_default=False, preserve_default=False,
), ),
migrations.AlterField( migrations.AlterField(
model_name='coursecompletion', model_name="coursecompletion",
name='completion_status', 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), 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( migrations.AddConstraint(
model_name='coursecompletion', model_name="coursecompletion",
constraint=models.UniqueConstraint(fields=('user', 'page', 'course_session'), name='course_completion_unique_user_page_key'), constraint=models.UniqueConstraint(
fields=("user", "page", "course_session"),
name="course_completion_unique_user_page_key",
),
), ),
] ]

View File

@ -0,0 +1,22 @@
# Generated by Django 3.2.13 on 2023-06-26 16:30
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("assignment", "0004_assignment_assignment_type"),
("learnpath", "0008_auto_20230626_1747"),
]
operations = [
migrations.AlterField(
model_name="learningcontentassignment",
name="content_assignment",
field=models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT, to="assignment.assignment"
),
),
]