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

Merge branch '256-add-simple-course-book-list' of...

Merge branch '256-add-simple-course-book-list' of edugit.org:aleksis/official/aleksis-app-alsijil into 256-add-simple-course-book-list
parents 6bdc3f34 b07a4284
No related branches found
No related tags found
2 merge requests!352Draft: Resolve "Add dialog with each lesson's students",!350Resolve "Add simple course book list"
Pipeline #178678 failed
from datetime import datetime from datetime import datetime
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.utils.timezone import localdate, localtime
import graphene import graphene
from graphene_django.types import DjangoObjectType from graphene_django.types import DjangoObjectType
...@@ -22,6 +23,7 @@ from aleksis.core.schema.base import ( ...@@ -22,6 +23,7 @@ from aleksis.core.schema.base import (
PermissionBatchPatchMixin, PermissionBatchPatchMixin,
PermissionsTypeMixin, PermissionsTypeMixin,
) )
from aleksis.core.util.core_helpers import get_site_preferences
from ..models import Documentation from ..models import Documentation
...@@ -170,34 +172,50 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation): ...@@ -170,34 +172,50 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation):
# Sadly, we can't use the update_or_create method since create_defaults # Sadly, we can't use the update_or_create method since create_defaults
# is only introduced in Django 5.0 # is only introduced in Django 5.0
if _id.startswith("DUMMY"): if _id.startswith("DUMMY"):
dummy, lesson_event_id, datetime_start, datetime_end = _id.split(";") dummy, lesson_event_id, datetime_start_iso, datetime_end_iso = _id.split(";")
lesson_event = LessonEvent.objects.get(id=lesson_event_id) lesson_event = LessonEvent.objects.get(id=lesson_event_id)
if not info.context.user.has_perm( datetime_start = datetime.fromisoformat(datetime_start_iso).astimezone(
lesson_event.timezone
)
datetime_end = datetime.fromisoformat(datetime_end_iso).astimezone(
lesson_event.timezone
)
if info.context.user.has_perm(
"alsijil.add_documentation_for_lesson_event_rule", lesson_event "alsijil.add_documentation_for_lesson_event_rule", lesson_event
) and (
get_site_preferences()["alsijil__allow_edit_future_documentations"] == "all"
or (
get_site_preferences()["alsijil__allow_edit_future_documentations"]
== "current_day"
and datetime_start.date() <= localdate()
)
or (
get_site_preferences()["alsijil__allow_edit_future_documentations"]
== "current_time"
and datetime_start <= localtime()
)
): ):
raise PermissionDenied() # Timezone removal is necessary due to ISO style offsets are no valid timezones.
# Instead, we take the timezone from the lesson_event and save it in a dedicated field.
# Timezone removal is necessary due to ISO style offsets are no valid timezones. obj = Documentation.objects.create(
# Instead, we take the timezone from the lesson_event and save it in a dedicated field. datetime_start=datetime_start,
obj = Documentation.objects.create( datetime_end=datetime_end,
datetime_start=datetime.fromisoformat(datetime_start).astimezone( lesson_event=lesson_event,
lesson_event.timezone course=lesson_event.course,
), subject=lesson_event.subject,
datetime_end=datetime.fromisoformat(datetime_end).astimezone(lesson_event.timezone), topic=doc.topic or "",
lesson_event=lesson_event, homework=doc.homework or "",
course=lesson_event.course, group_note=doc.group_note or "",
subject=lesson_event.subject, )
topic=doc.topic or "", if doc.teachers is not None:
homework=doc.homework or "", obj.teachers.add(*doc.teachers)
group_note=doc.group_note or "", else:
) obj.teachers.set(lesson_event.teachers.all())
if doc.teachers is not None: obj.save()
obj.teachers.add(*doc.teachers) return obj
else: raise PermissionDenied()
obj.teachers.set(lesson_event.teachers.all())
obj.save()
return obj
else: else:
obj = Documentation.objects.get(id=_id) obj = Documentation.objects.get(id=_id)
......
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