Skip to content
Snippets Groups Projects
Commit 54b1a660 authored by Julian's avatar Julian Committed by permcu
Browse files

Move documentation creation to model method

parent 3d54e105
No related branches found
No related tags found
1 merge request!361Resolve "Add statistics page for absences"
......@@ -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.
......
......@@ -97,13 +97,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.
Finish editing this message first!
Please register or to comment