Skip to content
Snippets Groups Projects
Commit a72163f5 authored by Julian's avatar Julian
Browse files

Move documentation creation to model method

parent d2159489
Branches
Tags
1 merge request!360Resolve "Add absence management to course book student dialog"
......@@ -680,6 +680,16 @@ class Documentation(CalendarEvent):
obj.save()
return obj
@classmethod
def get_or_create_by_id(cls, _id: str|int, user):
if _id.startswith("DUMMY"):
return cls.create_from_lesson_event(
user,
*cls.parse_dummy(_id),
)
return cls.objects.get(id=_id)
class ParticipationStatus(CalendarEvent):
"""A participation or absence record about a single person.
......
......@@ -109,13 +109,7 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation):
# Sadly, we can't use the update_or_create method since create_defaults
# is only introduced in Django 5.0
if _id.startswith("DUMMY"):
obj = Documentation.create_from_lesson_event(
info.context.user,
*Documentation.parse_dummy(_id),
)
else:
obj = Documentation.objects.get(id=_id)
obj = Documentation.get_or_create_by_id(_id, info.context.user)
if not info.context.user.has_perm("alsijil.edit_documentation_rule", obj):
raise PermissionDenied()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment