diff --git a/aleksis/apps/chronos/schema/__init__.py b/aleksis/apps/chronos/schema/__init__.py index 212a9330e02e77926c640d955898b31c562d95c1..4abeaef132e5bec552c53e1fa385f47205f467e3 100644 --- a/aleksis/apps/chronos/schema/__init__.py +++ b/aleksis/apps/chronos/schema/__init__.py @@ -1,3 +1,5 @@ +from datetime import timezone + import graphene from graphene_django import DjangoObjectType from graphene_django_cud.mutations import DjangoCreateMutation, DjangoPatchMutation @@ -71,6 +73,21 @@ class AmendLessonCreateMutation(DjangoCreateMutation): "comment", ) + @classmethod + def handle_datetime_start(cls, value, name, info) -> int: + value = value.replace(tzinfo=timezone.utc) + return value + + @classmethod + def handle_datetime_end(cls, value, name, info) -> int: + value = value.replace(tzinfo=timezone.utc) + return value + + @classmethod + def before_save(cls, root, info, input, obj): + obj.timezone = obj.amends.timezone + return obj + class AmendLessonPatchMutation(DjangoPatchMutation): class Meta: @@ -78,6 +95,21 @@ class AmendLessonPatchMutation(DjangoPatchMutation): permissions = ("chronos.edit_substitution_rule",) only_fields = ("subject", "teachers", "groups", "rooms", "cancelled", "comment") + @classmethod + def handle_datetime_start(cls, value, name, info) -> int: + value = value.replace(tzinfo=timezone.utc) + return value + + @classmethod + def handle_datetime_end(cls, value, name, info) -> int: + value = value.replace(tzinfo=timezone.utc) + return value + + @classmethod + def before_save(cls, root, info, input, id, obj): + obj.timezone = obj.amends.timezone + return obj + class TimetableType(graphene.Enum): TEACHER = "teacher"