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

Simplify if-statement

parent 9465d0cb
No related branches found
No related tags found
1 merge request!361Resolve "Add statistics page for absences"
...@@ -10,6 +10,7 @@ from django.db.models.query_utils import Q ...@@ -10,6 +10,7 @@ from django.db.models.query_utils import Q
from django.http import HttpRequest from django.http import HttpRequest
from django.urls import reverse from django.urls import reverse
from django.utils.formats import date_format from django.utils.formats import date_format
from django.utils.timezone import localdate, localtime
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.contrib.auth.models import User from django.contrib.auth.models import User
...@@ -584,7 +585,7 @@ class Documentation(CalendarEvent): ...@@ -584,7 +585,7 @@ class Documentation(CalendarEvent):
""" """
event_params = { event_params = {
"type": "PARTICIPANT", "type": "PARTICIPANT",
"obj_id": PERSON_ID, "obj_id": person,
} }
events = LessonEvent.get_single_events( events = LessonEvent.get_single_events(
...@@ -626,9 +627,9 @@ class Documentation(CalendarEvent): ...@@ -626,9 +627,9 @@ class Documentation(CalendarEvent):
""" Create a documentation from a lesson_event with start and end datetime. """ Create a documentation from a lesson_event with start and end datetime.
User is needed for permission checking. User is needed for permission checking.
""" """
if user.has_perm( if not user.has_perm(
"alsijil.add_documentation_for_lesson_event_rule", lesson_event "alsijil.add_documentation_for_lesson_event_rule", lesson_event
) and ( ) or not (
get_site_preferences()["alsijil__allow_edit_future_documentations"] == "all" get_site_preferences()["alsijil__allow_edit_future_documentations"] == "all"
or ( or (
get_site_preferences()["alsijil__allow_edit_future_documentations"] get_site_preferences()["alsijil__allow_edit_future_documentations"]
...@@ -641,45 +642,43 @@ class Documentation(CalendarEvent): ...@@ -641,45 +642,43 @@ class Documentation(CalendarEvent):
and datetime_start <= localtime() and datetime_start <= localtime()
) )
): ):
if lesson_event.amends: raise PermissionDenied()
if lesson_event.course:
course = lesson_event.course
else:
course = lesson_event.amends.course
if lesson_event.subject: if lesson_event.amends:
subject = lesson_event.subject if lesson_event.course:
else: course = lesson_event.course
subject = lesson_event.amends.subject else:
course = lesson_event.amends.course
if lesson_event.teachers: if lesson_event.subject:
teachers = lesson_event.teachers subject = lesson_event.subject
else: else:
teachers = lesson_event.amends.teachers subject = lesson_event.amends.subject
else:
course, subject, teachers = (
lesson_event.course,
lesson_event.subject,
lesson_event.teachers,
)
obj = cls.objects.create( if lesson_event.teachers:
datetime_start=datetime_start, teachers = lesson_event.teachers
datetime_end=datetime_end, else:
amends=lesson_event, teachers = lesson_event.amends.teachers
course=course, else:
subject=subject, course, subject, teachers = (
topic=doc.topic or "", lesson_event.course,
homework=doc.homework or "", lesson_event.subject,
group_note=doc.group_note or "", lesson_event.teachers,
) )
if doc.teachers is not None:
obj.teachers.add(*doc.teachers) obj = cls.objects.create(
else: datetime_start=datetime_start,
obj.teachers.set(teachers.all()) datetime_end=datetime_end,
obj.save() amends=lesson_event,
return obj course=course,
raise PermissionDenied() subject=subject,
topic="",
homework="",
group_note="",
)
obj.teachers.set(teachers.all())
obj.save()
return obj
class ParticipationStatus(CalendarEvent): 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