Skip to content
Snippets Groups Projects
Commit fbf25845 authored by permcu's avatar permcu
Browse files

Fix batch documentation mutation

parent 15926c5b
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"
...@@ -136,39 +136,43 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation): ...@@ -136,39 +136,43 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation):
documentations = graphene.List(DocumentationType) documentations = graphene.List(DocumentationType)
@classmethod @classmethod
def mutate(cls, root, info, input): def create_or_update(cls, info, doc):
for doc in input: id = doc.id
id = doc.id
# Sadly, we can't use the update_or_create method since create_defaults is only introduced in Django 5.0 # Sadly, we can't use the update_or_create method since create_defaults is only introduced in Django 5.0
if id.startswith("DUMMY"): if id.startswith("DUMMY"):
dummy, lesson_event_id, datetime_start, datetime_end = id.split(";") dummy, lesson_event_id, datetime_start, datetime_end = id.split(";")
lesson_event = LessonEvent.objects.get(id=lesson_event_id) lesson_event = LessonEvent.objects.get(id=lesson_event_id)
if not info.context.user.has_perm( if not info.context.user.has_perm(
"alsijil.add_documentation_for_lesson_event_rule", lesson_event "alsijil.add_documentation_for_lesson_event_rule", lesson_event
): ):
raise PermissionDenied() raise PermissionDenied()
obj = Documentation.objects.create( return Documentation.objects.create(
datetime_start=datetime.fromisoformat(datetime_start), datetime_start=datetime.fromisoformat(datetime_start),
datetime_end=datetime.fromisoformat(datetime_end), datetime_end=datetime.fromisoformat(datetime_end),
lesson_event=lesson_event, lesson_event=lesson_event,
course=lesson_event.course, course=lesson_event.course,
subject=lesson_event.subject, subject=lesson_event.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 "",
) # TODO: Add course & subject ) # TODO: Add course & subject
else: else:
obj = Documentation.objects.get(id=id) obj = Documentation.objects.get(id=id)
if not info.context.user.has_perm("alsijil.edit_documentation_rule", obj): if not info.context.user.has_perm("alsijil.edit_documentation_rule", obj):
raise PermissionDenied() raise PermissionDenied()
obj.topic = doc.topic or "" obj.topic = doc.topic or ""
obj.homework = doc.homework or "" obj.homework = doc.homework or ""
obj.group_note = doc.group_note or "" obj.group_note = doc.group_note or ""
obj.save() obj.save()
return obj
return DocumentationBatchCreateOrUpdateMutation(documentations=obj)
@classmethod
def mutate(cls, root, info, input):
objs = [cls.create_or_update(info, doc) for doc in input]
return DocumentationBatchCreateOrUpdateMutation(documentations=objs)
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