doorcontrol: Grant instructors access for ~1 hour around their class times
All checks were successful
Ruff / ruff (push) Successful in 57s
Test / test (push) Successful in 4m59s

Also the required foundation for #14
This commit is contained in:
Adam Goldsmith 2024-06-07 09:34:51 -04:00
parent d8e6a69719
commit 12271ef327

View File

@ -1,7 +1,10 @@
import dataclasses
import logging
from datetime import timedelta
from typing import TypedDict
from django.utils import timezone
from django_q.tasks import async_task
from cmsmanage.django_q2_helper import q_task_group
@ -62,6 +65,17 @@ class DoorMember:
if getattr(member, attribute_rule.access_field)
}
# grant instructors access for ~1 hour around their class times
if hasattr(member, "eventinstructor") and getattr(member, door.access_field):
now = timezone.now()
margin = timedelta(hours=1)
if member.eventinstructor.eventext_set.filter(
occurred=True,
meeting_times__start__lt=now + margin,
meeting_times__end__gt=now - margin,
).exists():
reasons_and_schedules["Instructor for Active Class"] = "Unlimited"
reasons = sorted(reasons_and_schedules.keys())
return cls(