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

Move documentation creation to model method

parent 4cd4ea45
No related branches found
No related tags found
1 merge request!362Resolve "Add personal note management dialog in course book"
......@@ -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.
Finish editing this message first!
Please register or to comment