diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py index 0a914175615677d0371a2c90311485dd928d9b28..ad6aa5c4f7a5a93b40fe1e37e53837be344571e1 100644 --- a/aleksis/apps/alsijil/models.py +++ b/aleksis/apps/alsijil/models.py @@ -10,6 +10,7 @@ from django.db.models.query_utils import Q from django.http import HttpRequest from django.urls import reverse from django.utils.formats import date_format +from django.utils.timezone import localdate, localtime from django.utils.translation import gettext_lazy as _ from django.contrib.auth.models import User @@ -584,7 +585,7 @@ class Documentation(CalendarEvent): """ event_params = { "type": "PARTICIPANT", - "obj_id": PERSON_ID, + "obj_id": person, } events = LessonEvent.get_single_events( @@ -626,9 +627,9 @@ class Documentation(CalendarEvent): """ Create a documentation from a lesson_event with start and end datetime. User is needed for permission checking. """ - if user.has_perm( + if not user.has_perm( "alsijil.add_documentation_for_lesson_event_rule", lesson_event - ) and ( + ) or not ( get_site_preferences()["alsijil__allow_edit_future_documentations"] == "all" or ( get_site_preferences()["alsijil__allow_edit_future_documentations"] @@ -641,45 +642,43 @@ class Documentation(CalendarEvent): and datetime_start <= localtime() ) ): - if lesson_event.amends: - if lesson_event.course: - course = lesson_event.course - else: - course = lesson_event.amends.course + raise PermissionDenied() - if lesson_event.subject: - subject = lesson_event.subject - else: - subject = lesson_event.amends.subject + if lesson_event.amends: + if lesson_event.course: + course = lesson_event.course + else: + course = lesson_event.amends.course - if lesson_event.teachers: - teachers = lesson_event.teachers - else: - teachers = lesson_event.amends.teachers - else: - course, subject, teachers = ( - lesson_event.course, - lesson_event.subject, - lesson_event.teachers, - ) + if lesson_event.subject: + subject = lesson_event.subject + else: + subject = lesson_event.amends.subject - obj = cls.objects.create( - datetime_start=datetime_start, - datetime_end=datetime_end, - amends=lesson_event, - course=course, - subject=subject, - topic=doc.topic or "", - homework=doc.homework or "", - group_note=doc.group_note or "", - ) - if doc.teachers is not None: - obj.teachers.add(*doc.teachers) - else: - obj.teachers.set(teachers.all()) - obj.save() - return obj - raise PermissionDenied() + if lesson_event.teachers: + teachers = lesson_event.teachers + else: + teachers = lesson_event.amends.teachers + else: + course, subject, teachers = ( + lesson_event.course, + lesson_event.subject, + lesson_event.teachers, + ) + + obj = cls.objects.create( + datetime_start=datetime_start, + datetime_end=datetime_end, + amends=lesson_event, + course=course, + subject=subject, + topic="", + homework="", + group_note="", + ) + obj.teachers.set(teachers.all()) + obj.save() + return obj class ParticipationStatus(CalendarEvent):