From 39a85c05591a91fe095674cddf9695e32c2e3e73 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Sat, 2 Sep 2023 19:19:34 +0200 Subject: [PATCH] Correctly set timezones with amended lesson events --- aleksis/apps/chronos/schema/__init__.py | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/aleksis/apps/chronos/schema/__init__.py b/aleksis/apps/chronos/schema/__init__.py index 212a9330..4abeaef1 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" -- GitLab