Skip to content
Snippets Groups Projects
Verified Commit 06196560 authored by permcu's avatar permcu Committed by Jonathan Weth
Browse files

Implement SubstitutionsType for substitutions-query

This ports the logic in the substitutions-print-templates to a graphql-type.
parent abfa222e
No related branches found
No related tags found
1 merge request!373Resolve "Substitutions table for new data model"
...@@ -8,25 +8,31 @@ query substitutionsForDate ($date: Date!) { ...@@ -8,25 +8,31 @@ query substitutionsForDate ($date: Date!) {
shortName shortName
} }
substitutions { substitutions {
groups { oldGroups {
old { shortName
shortName }
} newGroups {
new { shortName
shortName
}
} }
startSlot startSlot
endSlot endSlot
startTime startTime
endTime endTime
wholeDay oldTeachers {
teachers {
shortName shortName
fullName fullName
} }
subject newTeachers {
rooms { shortName
fullName
}
oldSubject
newSubject
oldRooms {
shortName
name
}
newRooms {
shortName shortName
name name
} }
......
...@@ -9,6 +9,7 @@ from aleksis.core.schema.base import ( ...@@ -9,6 +9,7 @@ from aleksis.core.schema.base import (
) )
from aleksis.core.schema.person import PersonType from aleksis.core.schema.person import PersonType
from aleksis.core.schema.group import GroupType from aleksis.core.schema.group import GroupType
from aleksis.core.schema.room import RoomType
from ..models import LessonEvent from ..models import LessonEvent
from ..util.chronos_helpers import get_groups, get_rooms, get_teachers, get_next_relevant_day from ..util.chronos_helpers import get_groups, get_rooms, get_teachers, get_next_relevant_day
...@@ -125,36 +126,95 @@ class TimetableObjectType(graphene.ObjectType): ...@@ -125,36 +126,95 @@ class TimetableObjectType(graphene.ObjectType):
return f"{root.type.value}-{root.id}" return f"{root.type.value}-{root.id}"
class SubstitutionGroupsType(graphene.ObjectType):
old = graphene.List(GroupType)
new = graphene.List(GroupType)
def resolve_old(root, info):
if root.groups.all() and root.amends.groups.all():
return root.amends.groups.all()
else:
return []
def resolve_new(root, info):
return root.groups.all() or root.amends.groups.all()
class SubstitutionType(graphene.ObjectType): class SubstitutionType(graphene.ObjectType):
"""This type contains the logic also contained in the pdf templates.""" """This type contains the logic also contained in the pdf templates."""
groups = graphene.List(SubstitutionGroupsType) old_groups = graphene.List(GroupType)
new_groups = graphene.List(GroupType)
start_slot = graphene.Int() start_slot = graphene.Int()
end_slot = graphene.Int() end_slot = graphene.Int()
start_time = graphene.Time() start_time = graphene.Time()
end_time = graphene.Time() end_time = graphene.Time()
whole_day = graphene.Boolean() old_teachers = graphene.List(PersonType)
teachers = graphene.List(PersonType) new_teachers = graphene.List(PersonType)
subject = graphene.String() old_subject = graphene.String()
rooms = graphene.List(RoomType) new_subject = graphene.String()
old_rooms = graphene.List(RoomType)
new_rooms = graphene.List(RoomType)
cancelled = graphene.Boolean() cancelled = graphene.Boolean()
comment = graphene.String() comment = graphene.String()
def resolve_groups(root, info): # TODO: Extract old/new blueprint?
return root['REFERENCE_OBJECT']
def resolve_old_groups(root, info):
le = root['REFERENCE_OBJECT']
return le.amends.groups.all() or le.groups.all()
def resolve_new_groups(root, info):
le = root['REFERENCE_OBJECT']
if le.groups.all() and le.amends.groups.all():
return le.groups.all()
else:
return []
def resolve_start_slot(root, info):
return root['REFERENCE_OBJECT'].slot_number_start
def resolve_end_slot(root, info):
return root['REFERENCE_OBJECT'].slot_number_end
def resolve_start_time(root, info):
return root['DTSTART'].dt.time()
def resolve_end_time(root, info):
return root['DTEND'].dt.time()
def resolve_old_teachers(root,info):
le = root['REFERENCE_OBJECT']
return le.amends.teachers.all() or le.teachers.all()
def resolve_new_teachers(root, info):
le = root['REFERENCE_OBJECT']
if le.teachers.all() and le.amends.teachers.all():
return le.teachers.all()
else:
return []
def resolve_old_subject(root, info):
le = root['REFERENCE_OBJECT']
if le.name == "supervision":
return "SUPERVISION"
elif not le.amends.subject and not le.subject:
return le.amends.title
else:
return le.amends.subject or le.subject
def resolve_new_subject(root, info):
le = root['REFERENCE_OBJECT']
if le.name == "supervision":
return None
elif not le.amends.subject and not le.subject:
return le.title
elif le.subject and le.samends.subject:
return le.subject
else:
return []
def resolve_old_rooms(root, object):
le = root['REFERENCE_OBJECT']
return le.amends.rooms.all() or le.rooms.all()
def resolve_new_rooms(root, info):
le = root['REFERENCE_OBJECT']
if le.rooms.all() and le.amends.rooms.all():
return le.rooms.all()
else:
return []
def resolve_cancelled(root, info):
return root['REFERENCE_OBJECT'].cancelled
def resolve_comment(root, info):
return root['REFERENCE_OBJECT'].comment
class SubstitutionsForDateType(graphene.ObjectType): class SubstitutionsForDateType(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