Skip to content
Snippets Groups Projects
Verified Commit fd036dc1 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Convert datetimes on substitution creation to UTC to transfer data correctly

parent 582b606a
No related branches found
No related tags found
1 merge request!310Resolve "Implement Vue substitution frontend"
Pipeline #146493 failed
......@@ -237,8 +237,8 @@ export default {
return {
...item,
amends: this.selectedEvent.meta.id,
datetimeStart: this.selectedEvent.startDateTime.toISO(),
datetimeEnd: this.selectedEvent.endDateTime.toISO(),
datetimeStart: this.selectedEvent.startDateTime.toUTC().toISO(),
datetimeEnd: this.selectedEvent.endDateTime.toUTC().toISO(),
};
},
transformPatchData(item) {
......
......@@ -57,7 +57,31 @@ class LessonEventType(DjangoObjectType):
)
class AmendLessonCreateMutation(DjangoCreateMutation):
class DatetimeTimezoneMixin:
"""Handle datetimes for mutations with CalendarEvent objects.
Since the client sends timezone information as ISO string
which only includes an offset (+00:00 UTC). Because an offset
is no valid timezone, we set UTC as timezone directly.
"""
@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 AmendLessonCreateMutation(DatetimeTimezoneMixin, DjangoCreateMutation):
class Meta:
model = LessonEvent
permissions = ("chronos.edit_substitution_rule",)
......@@ -74,14 +98,13 @@ class AmendLessonCreateMutation(DjangoCreateMutation):
)
class AmendLessonPatchMutation(DjangoPatchMutation):
class AmendLessonPatchMutation(DatetimeTimezoneMixin, DjangoPatchMutation):
class Meta:
model = LessonEvent
permissions = ("chronos.edit_substitution_rule",)
only_fields = ("subject", "teachers", "groups", "rooms", "cancelled", "comment")
class TimetableType(graphene.Enum):
TEACHER = "teacher"
GROUP = "group"
......
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