Skip to content
Snippets Groups Projects
Commit 98647a7f authored by Julian's avatar Julian
Browse files

Add teachers to DocumentationType

parent 77b5d4c6
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"
......@@ -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)
......
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