|
1 | 1 | 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 |
5 | 9 |
|
| 10 | +from conditional.models.models import CurrentCoops |
| 11 | +from conditional.models.models import OnFloorStatusAssigned |
6 | 12 |
|
7 | 13 | @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 | + |
9 | 19 | ofm = [
|
10 | 20 | {
|
11 | 21 | 'uid': m.uid,
|
12 | 22 | 'time': m.onfloor_granted,
|
13 | 23 | '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 | + }) |
16 | 45 |
|
17 | 46 | # sort by housing points then by time in queue
|
18 | 47 | ofm.sort(key=lambda m: m['time'])
|
19 | 48 | ofm.sort(key=lambda m: m['points'], reverse=True)
|
20 | 49 |
|
| 50 | + return ofm |
| 51 | + |
| 52 | +def get_housing_queue(): |
| 53 | + ofm = __get_ofm__() |
| 54 | + |
21 | 55 | queue = [m['uid'] for m in ofm if ldap_get_room_number(m['uid']) == "N/A" and ldap_is_current_student(m['uid'])]
|
22 | 56 |
|
23 | 57 | return queue
|
24 | 58 |
|
25 | 59 |
|
26 | 60 | 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__() |
38 | 62 |
|
39 | 63 | queue = [
|
40 | 64 | {
|
|
0 commit comments