22
33from conditional .models .models import InHousingQueue
44from conditional .models .models import OnFloorStatusAssigned
5- from conditional .util .ldap import ldap_get_current_students
6- from conditional .util .ldap import ldap_is_onfloor
5+ from conditional .util .ldap import ldap_get_member , ldap_is_current_student
76
87
98def get_housing_queue (is_eval_director = False ):
@@ -12,23 +11,34 @@ def get_housing_queue(is_eval_director=False):
1211 # and {'time': <datetime obj>} is the value. We are doing a left
1312 # outer join on the two tables to get a single result that has
1413 # both the member's UID and their on-floor datetime.
15- in_queue = {entry .uid : {'time' : entry .onfloor_granted } for entry
16- in InHousingQueue .query .outerjoin (OnFloorStatusAssigned ,
17- OnFloorStatusAssigned .uid == InHousingQueue .uid )\
18- .with_entities (InHousingQueue .uid , OnFloorStatusAssigned .onfloor_granted )\
19- .all ()}
14+ in_queue = {
15+ entry .uid : {
16+ 'time' : entry .onfloor_granted
17+ } for entry in InHousingQueue .query .outerjoin (
18+ OnFloorStatusAssigned ,
19+ OnFloorStatusAssigned .uid == InHousingQueue .uid
20+ ).with_entities (
21+ InHousingQueue .uid ,
22+ OnFloorStatusAssigned .onfloor_granted
23+ ).all ()
24+ }
25+
26+ # CSHMember accounts that are in queue
27+ potential_accounts = [ldap_get_member (username ) for username in in_queue ]
2028
2129 # Populate a list of dictionaries containing the name, username,
22- # and on-floor datetime for each member who has on-floor status,
23- # is not already assigned to a room and is in the above query.
24- queue = [{"uid" : account .uid ,
25- "name" : account .cn ,
26- "points" : account .housingPoints ,
27- "time" : in_queue .get (account .uid , {}).get ('time' , datetime .now ()) or datetime .now (),
28- "in_queue" : account .uid in in_queue }
29- for account in ldap_get_current_students ()
30- if ldap_is_onfloor (account ) and (is_eval_director or account .uid in in_queue )
31- and account .roomNumber is None ]
30+ # and on-floor datetime for each current studetn who has on-floor status
31+ # and is not already assigned to a room
32+ queue = [
33+ {
34+ "uid" : account .uid ,
35+ "name" : account .cn ,
36+ "points" : account .housingPoints ,
37+ "time" : in_queue .get (account .uid , {}).get ('time' , datetime .now ()) or datetime .now (),
38+ "in_queue" : account .uid in in_queue
39+ } for account in potential_accounts
40+ if ldap_is_current_student (account ) and (is_eval_director or account .roomNumber is None )
41+ ]
3242
3343 # Sort based on time (ascending) and then points (decending).
3444 queue .sort (key = lambda m : m ['time' ])
@@ -40,7 +50,7 @@ def get_housing_queue(is_eval_director=False):
4050def get_queue_position (username ):
4151 queue = get_housing_queue ()
4252 try :
43- index = next (index for (index , d ) in enumerate (get_housing_queue () )
53+ index = next (index for (index , d ) in enumerate (queue )
4454 if d ["uid" ] == username ) + 1
4555 except (KeyError , StopIteration ):
4656 index = None
0 commit comments