Skip to content
Snippets Groups Projects
Commit b2f54874 authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Add proper handling of documentations of substitution lessons

parent 5bf85bf3
No related branches found
No related tags found
2 merge requests!352Draft: Resolve "Add dialog with each lesson's students",!350Resolve "Add simple course book list"
...@@ -41,6 +41,19 @@ query documentationsForCoursebook( ...@@ -41,6 +41,19 @@ query documentationsForCoursebook(
id id
amends { amends {
id id
teachers {
id
shortName
fullName
avatarContentUrl
}
subject {
id
name
shortName
colourFg
colourBg
}
} }
cancelled cancelled
} }
......
...@@ -31,7 +31,15 @@ import PersonChip from "aleksis.core/components/person/PersonChip.vue"; ...@@ -31,7 +31,15 @@ import PersonChip from "aleksis.core/components/person/PersonChip.vue";
:subject="documentation.subject" :subject="documentation.subject"
v-bind="compact ? dialogActivator.attrs : {}" v-bind="compact ? dialogActivator.attrs : {}"
v-on="compact ? dialogActivator.on : {}" v-on="compact ? dialogActivator.on : {}"
/> />
<subject-chip
v-if="documentation?.lessonEvent?.amends?.subject && documentation.lessonEvent.amends.subject.id !== documentation.subject.id"
:subject="documentation.lessonEvent.amends.subject"
v-bind="compact ? dialogActivator.attrs : {}"
v-on="compact ? dialogActivator.on : {}"
class="text-decoration-line-through"
disabled
/>
<div :class="{ 'd-flex align-center flex-wrap gap': true }"> <div :class="{ 'd-flex align-center flex-wrap gap': true }">
<person-chip <person-chip
v-for="teacher in documentation.teachers" v-for="teacher in documentation.teachers"
...@@ -39,7 +47,16 @@ import PersonChip from "aleksis.core/components/person/PersonChip.vue"; ...@@ -39,7 +47,16 @@ import PersonChip from "aleksis.core/components/person/PersonChip.vue";
no-link no-link
v-bind="compact ? dialogActivator.attrs : {}" v-bind="compact ? dialogActivator.attrs : {}"
v-on="compact ? dialogActivator.on : {}" v-on="compact ? dialogActivator.on : {}"
/> />
<person-chip
v-for="teacher in amendedTeachers"
:person="teacher"
no-link
v-bind="compact ? dialogActivator.attrs : {}"
v-on="compact ? dialogActivator.on : {}"
class="text-decoration-line-through"
disabled
/>
</div> </div>
</div> </div>
</template> </template>
...@@ -64,6 +81,12 @@ export default { ...@@ -64,6 +81,12 @@ export default {
largeGrid() { largeGrid() {
return this.compact && !this.$vuetify.breakpoint.mobile; return this.compact && !this.$vuetify.breakpoint.mobile;
}, },
amendedTeachers() {
if (this.documentation?.lessonEvent?.amends?.teachers && this.documentation.lessonEvent.amends.teachers.length) {
return this.documentation.lessonEvent.amends.teachers.filter((at) => !this.documentation.teachers.includes((t) => t.id === at.id));
}
return [];
}
}, },
}; };
</script> </script>
......
...@@ -582,12 +582,25 @@ class Documentation(CalendarEvent): ...@@ -582,12 +582,25 @@ class Documentation(CalendarEvent):
continue continue
docs.append(doc) docs.append(doc)
else: else:
if event_reference_obj.amends:
if event_reference_obj.course:
course = event_reference_obj.course
else:
course = event_reference_obj.amends.course
if event_reference_obj.subject:
subject = event_reference_obj.subject
else:
subject = event_reference_obj.amends.subject
else:
course, subject = event_reference_obj.course, event_reference_obj.subject
docs.append( docs.append(
cls( cls(
pk=f"DUMMY;{event_reference_obj.id};{event['DTSTART'].dt.isoformat()};{event['DTEND'].dt.isoformat()}", pk=f"DUMMY;{event_reference_obj.id};{event['DTSTART'].dt.isoformat()};{event['DTEND'].dt.isoformat()}",
lesson_event=event_reference_obj, lesson_event=event_reference_obj,
course=event_reference_obj.course, course=course,
subject=event_reference_obj.subject, subject=subject,
datetime_start=event["DTSTART"].dt, datetime_start=event["DTSTART"].dt,
datetime_end=event["DTEND"].dt, datetime_end=event["DTEND"].dt,
) )
......
...@@ -55,6 +55,11 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp ...@@ -55,6 +55,11 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
def resolve_teachers(root: Documentation, info, **kwargs): def resolve_teachers(root: Documentation, info, **kwargs):
if not str(root.pk).startswith("DUMMY") and hasattr(root, "teachers"): if not str(root.pk).startswith("DUMMY") and hasattr(root, "teachers"):
return root.teachers return root.teachers
elif root.lesson_event.amends:
if root.lesson_event.teachers:
return root.lesson_event.teachers
else:
return root.lesson_event.amends.teachers
return root.lesson_event.teachers return root.lesson_event.teachers
@staticmethod @staticmethod
...@@ -118,12 +123,30 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation): ...@@ -118,12 +123,30 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation):
and datetime_start <= localtime() and datetime_start <= localtime()
) )
): ):
if lesson_event.amends:
if lesson_event.course:
course = lesson_event.course
else:
course = lesson_event.amends.course
if lesson_event.subject:
subject = lesson_event.subject
else:
subject = lesson_event.amends.subject
if lesson_event.teachers:
teachers = lesson_event.teachers
else:
teachers = lesson_event.amends.teachers
else:
course, subject, teachers = lesson_event.course, lesson_event.subject, lesson_event.teachers
obj = Documentation.objects.create( obj = Documentation.objects.create(
datetime_start=datetime_start, datetime_start=datetime_start,
datetime_end=datetime_end, datetime_end=datetime_end,
lesson_event=lesson_event, lesson_event=lesson_event,
course=lesson_event.course, course=course,
subject=lesson_event.subject, subject=subject,
topic=doc.topic or "", topic=doc.topic or "",
homework=doc.homework or "", homework=doc.homework or "",
group_note=doc.group_note or "", group_note=doc.group_note or "",
...@@ -131,7 +154,7 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation): ...@@ -131,7 +154,7 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation):
if doc.teachers is not None: if doc.teachers is not None:
obj.teachers.add(*doc.teachers) obj.teachers.add(*doc.teachers)
else: else:
obj.teachers.set(lesson_event.teachers.all()) obj.teachers.set(teachers.all())
obj.save() obj.save()
return obj return obj
raise PermissionDenied() raise PermissionDenied()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment