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

Simplify if-statement

parent 52a293ba
No related branches found
No related tags found
1 merge request!360Resolve "Add absence management to course book student dialog"
......@@ -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):
......
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