diff --git a/doorcontrol/tasks/update_doors.py b/doorcontrol/tasks/update_doors.py index 077e485..097a67b 100644 --- a/doorcontrol/tasks/update_doors.py +++ b/doorcontrol/tasks/update_doors.py @@ -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(