Skip to content

Commit 37ee6dc

Browse files
authored
Merge pull request #76 from liam-middlebrook/fix-housing-queue
Fix housing queue
2 parents 4f1326e + 3765337 commit 37ee6dc

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

conditional/util/housing.py

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,64 @@
11
from functools import lru_cache
2-
from conditional.util.ldap import ldap_get_housing_points, ldap_get_room_number, ldap_get_name, ldap_is_active, \
3-
ldap_is_current_student
4-
from conditional.models import models
2+
from datetime import datetime
3+
from conditional.util.ldap import ldap_get_housing_points
4+
from conditional.util.ldap import ldap_get_room_number
5+
from conditional.util.ldap import ldap_get_name
6+
from conditional.util.ldap import ldap_is_active
7+
from conditional.util.ldap import ldap_get_onfloor_members
8+
from conditional.util.ldap import ldap_is_current_student
59

10+
from conditional.models.models import CurrentCoops
11+
from conditional.models.models import OnFloorStatusAssigned
612

713
@lru_cache(maxsize=1024)
8-
def get_housing_queue():
14+
def __get_ofm__():
15+
16+
# check that everyone in onfloor has onfloorstatus
17+
onfloors = [uids['uid'][0].decode('utf-8') for uids in ldap_get_onfloor_members()]
18+
919
ofm = [
1020
{
1121
'uid': m.uid,
1222
'time': m.onfloor_granted,
1323
'points': ldap_get_housing_points(m.uid)
14-
} for m in models.OnFloorStatusAssigned.query.all()
15-
if ldap_is_active(m.uid)]
24+
} for m in OnFloorStatusAssigned.query.all()
25+
if ldap_is_active(m.uid)
26+
or CurrentCoops.query.filter(
27+
CurrentCoops.uid == m.uid and CurrentCoops.active
28+
).first() is not None]
29+
30+
# Add everyone who has a discrepancy in LDAP and OnFloorStatusAssigned
31+
for member in onfloors:
32+
if OnFloorStatusAssigned.query.filter(OnFloorStatusAssigned.uid == member).first() is None:
33+
ofsa = OnFloorStatusAssigned(member, datetime.min)
34+
active = ldap_is_active(ofsa.uid)
35+
coop = CurrentCoops.query.filter(CurrentCoops.uid == ofsa.uid).first()
36+
coop = coop != None and coop.active
37+
38+
if active or coop:
39+
ofm.append(
40+
{
41+
'uid': ofsa.uid,
42+
'time': ofsa.onfloor_granted,
43+
'points': ldap_get_housing_points(ofsa.uid)
44+
})
1645

1746
# sort by housing points then by time in queue
1847
ofm.sort(key=lambda m: m['time'])
1948
ofm.sort(key=lambda m: m['points'], reverse=True)
2049

50+
return ofm
51+
52+
def get_housing_queue():
53+
ofm = __get_ofm__()
54+
2155
queue = [m['uid'] for m in ofm if ldap_get_room_number(m['uid']) == "N/A" and ldap_is_current_student(m['uid'])]
2256

2357
return queue
2458

2559

2660
def get_queue_with_points():
27-
ofm = [
28-
{
29-
'uid': m.uid,
30-
'time': m.onfloor_granted,
31-
'points': ldap_get_housing_points(m.uid)
32-
} for m in models.OnFloorStatusAssigned.query.all()
33-
if ldap_is_active(m.uid)]
34-
35-
# sort by housing points then by time in queue
36-
ofm.sort(key=lambda m: m['time'])
37-
ofm.sort(key=lambda m: m['points'], reverse=True)
61+
ofm = __get_ofm__()
3862

3963
queue = [
4064
{

0 commit comments

Comments
 (0)