From 12271ef3273eaab481f79e929e37156f64b47ed4 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 7 Jun 2024 09:34:51 -0400 Subject: [PATCH] doorcontrol: Grant instructors access for ~1 hour around their class times Also the required foundation for #14 --- doorcontrol/tasks/update_doors.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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(