Finnish check_access
This commit is contained in:
@@ -35,15 +35,20 @@ def isDoorOpen():
|
||||
def checkAccess(uuid: str, db: Session = Depends(get_session)):
|
||||
try:
|
||||
current_weekday = datetime.datetime.weekday(datetime.date.today())
|
||||
print(f"current day is {current_weekday}")
|
||||
current_time = datetime.datetime.now()
|
||||
card = db.exec(select(Card).where(Card.uuid == uuid)).one()
|
||||
for auth in card.group.accessauths:
|
||||
print(f"checking auth: {auth.name}")
|
||||
for timetable in auth.timetables:
|
||||
print(f"timetable date is {timetable.weekday - 1}")
|
||||
if current_weekday == timetable.weekday - 1:
|
||||
return True
|
||||
return False
|
||||
print(f" checking timetable {timetable.id}")
|
||||
print(f" comparing weekday: CUR:{current_weekday} TT:{timetable.weekday}")
|
||||
if current_weekday == timetable.weekday:
|
||||
starttime = datetime.datetime.combine(datetime.date.today(), timetable.starttime)
|
||||
endtime = starttime + datetime.timedelta(minutes=timetable.duration)
|
||||
print(f" comparing time: Start:{starttime} Current:{current_time} End:{endtime}")
|
||||
if starttime < current_time < endtime:
|
||||
return True
|
||||
return False
|
||||
except exc.NoResultFound:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user