doorcontrol: Grant instructors access for ~1 hour around their class times
Some checks failed
Test / test (push) Has been cancelled
Ruff / ruff (push) Has been cancelled

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

View File

@ -1,7 +1,10 @@
import dataclasses import dataclasses
import logging import logging
from datetime import timedelta
from typing import TypedDict from typing import TypedDict
from django.utils import timezone
from django_q.tasks import async_task from django_q.tasks import async_task
from cmsmanage.django_q2_helper import q_task_group from cmsmanage.django_q2_helper import q_task_group
@ -62,6 +65,17 @@ class DoorMember:
if getattr(member, attribute_rule.access_field) 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"] = "Active Class"
reasons = sorted(reasons_and_schedules.keys()) reasons = sorted(reasons_and_schedules.keys())
return cls( return cls(