diff --git a/aleksis/apps/alsijil/schema/documentation.py b/aleksis/apps/alsijil/schema/documentation.py index 71ad9c468770d0952fb7990c7f14c3ea5d23ee25..6577704e0b3a6e46e43d7caff67992abe3f8b3d4 100644 --- a/aleksis/apps/alsijil/schema/documentation.py +++ b/aleksis/apps/alsijil/schema/documentation.py @@ -38,6 +38,7 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp "datetime_end", "date_start", "date_end", + "teachers", ) filter_fields = { "id": ["exact", "lte", "gte"], @@ -47,6 +48,12 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp course = graphene.Field(CourseType, required=False) subject = graphene.Field(SubjectType, required=False) + @staticmethod + def resolve_teachers(root: Documentation, info, **kwargs): + if not str(root.pk).startswith("DUMMY") and hasattr(root, "teachers"): + return root.teachers + return root.course.teachers + @classmethod def get_queryset(cls, queryset, info): return get_objects_for_user(info.context.user, "alsijil.view_documentation", queryset) @@ -129,6 +136,7 @@ class DocumentationInputType(graphene.InputObjectType): id = graphene.ID(required=True) course = graphene.ID(required=False) subject = graphene.ID(required=False) + teachers = graphene.List(graphene.ID, required=False) topic = graphene.String(required=False) homework = graphene.String(required=False) @@ -158,7 +166,7 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation): # Timezone removal is necessary due to ISO style offsets are no valid timezones. # Instead, we take the timezone from the lesson_event and save it in a dedicated field. - return Documentation.objects.create( + obj = Documentation.objects.create( datetime_start=datetime.fromisoformat(datetime_start).replace(tzinfo=timezone.utc), datetime_end=datetime.fromisoformat(datetime_end).replace(tzinfo=timezone.utc), timezone=lesson_event.timezone, @@ -169,6 +177,12 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation): homework=doc.homework or "", group_note=doc.group_note or "", ) + if doc.teachers is not None: + obj.teachers.add(*doc.teachers) + else: + obj.teachers.set(lesson_event.course.teachers) + obj.save() + return obj else: obj = Documentation.objects.get(id=_id)