Skip to content
Snippets Groups Projects
Verified Commit d706fa56 authored by Julian's avatar Julian Committed by magicfelix
Browse files

Update schema to support editing and creation of personal notes

parent 8aff9e8d
No related branches found
No related tags found
1 merge request!284Draft: Redesign entering of lesson documentation
......@@ -4,7 +4,7 @@ from graphene_django.forms.mutation import DjangoModelFormMutation
from aleksis.apps.chronos.models import LessonPeriod
from aleksis.core.models import Person, Group
from .forms import LessonDocumentationForm, PersonalNoteForm
from .forms import LessonDocumentationForm
from .models import ExcuseType, LessonDocumentation, PersonalNote, ExtraMark
......@@ -58,18 +58,13 @@ class LessonDocumentationMutation(DjangoModelFormMutation):
form_class = LessonDocumentationForm
class PersonalNoteMutation(DjangoModelFormMutation):
personal_note = graphene.Field(PersonalNoteType)
class Meta:
form_class = PersonalNoteForm
class CreatePersonalNoteMutation(graphene.Mutation):
class PersonalNoteMutation(graphene.Mutation):
class Arguments:
person_id = graphene.ID(required=True)
lesson_documentation = graphene.ID(required=True)
personal_note_id = graphene.ID(required=False) # Update or create personal note
late = graphene.Int(required=False)
absent = graphene.Boolean(required=False)
excused = graphene.Boolean(required=False)
......@@ -86,6 +81,7 @@ class CreatePersonalNoteMutation(graphene.Mutation):
info,
person_id,
lesson_documentation,
personal_note_id=None,
late=0,
absent=False,
excused=False,
......@@ -95,32 +91,41 @@ class CreatePersonalNoteMutation(graphene.Mutation):
):
if extra_marks is None:
extra_marks = []
person = Person.objects.get(pk=person_id)
lesson_documentation = LessonDocumentation.objects.get(pk=lesson_documentation)
extra_marks = ExtraMark.objects.filter(pk__in=extra_marks)
personal_note = PersonalNote.objects.create(
personal_note, created = PersonalNote.objects.get_or_create(
person=person,
event=lesson_documentation.event,
extra_lesson=lesson_documentation.extra_lesson,
lesson_period=lesson_documentation.lesson_period,
late=late,
absent=absent,
excused=excused,
excuse_type=excuse_type,
remarks=remarks,
week=lesson_documentation.week,
year=lesson_documentation.year,
)
if late:
personal_note.late = late
if absent is not None:
personal_note.absent = absent
if excused is not None:
personal_note.excused = excused
if excuse_type:
personal_note.excuse_type = ExcuseType.objects.get(pk=excuse_type)
if remarks:
personal_note.remarks = remarks
personal_note.save()
extra_marks = ExtraMark.objects.filter(pk__in=extra_marks)
personal_note.extra_marks.set(extra_marks)
personal_note.groups_of_person.set(person.member_of.all())
personal_note.save()
return CreatePersonalNoteMutation(personal_note=personal_note)
return PersonalNoteMutation(personal_note=personal_note)
class Mutation(graphene.ObjectType):
update_lesson_documentation = LessonDocumentationMutation.Field()
create_personal_note = CreatePersonalNoteMutation.Field()
update_personal_note = PersonalNoteMutation.Field()
update_or_create_personal_note = PersonalNoteMutation.Field()
# update_personal_note = PersonalNoteMutation.Field()
class Query(graphene.ObjectType):
......
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