|
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 OnFloorStatusAssigned |
6 | 11 |
|
| 12 | +from conditional import db |
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 | + |
| 19 | + # this is bad and we shouldn't do this every time |
| 20 | + for member in onfloors: |
| 21 | + if OnFloorStatusAssigned.query.filter(OnFloorStatusAssigned.uid == member).first() is None: |
| 22 | + db.session.add(OnFloorStatusAssigned(member, datetime.min)) |
| 23 | + |
| 24 | + db.session.flush() |
| 25 | + db.session.commit() |
9 | 26 | ofm = [
|
10 | 27 | {
|
11 | 28 | 'uid': m.uid,
|
12 | 29 | 'time': m.onfloor_granted,
|
13 | 30 | 'points': ldap_get_housing_points(m.uid)
|
14 |
| - } for m in models.OnFloorStatusAssigned.query.all() |
| 31 | + } for m in OnFloorStatusAssigned.query.all() |
15 | 32 | if ldap_is_active(m.uid)]
|
16 | 33 |
|
17 | 34 | # sort by housing points then by time in queue
|
18 | 35 | ofm.sort(key=lambda m: m['time'])
|
19 | 36 | ofm.sort(key=lambda m: m['points'], reverse=True)
|
20 | 37 |
|
| 38 | + return ofm |
| 39 | + |
| 40 | +def get_housing_queue(): |
| 41 | + ofm = __get_ofm__() |
| 42 | + |
21 | 43 | queue = [m['uid'] for m in ofm if ldap_get_room_number(m['uid']) == "N/A" and ldap_is_current_student(m['uid'])]
|
22 | 44 |
|
23 | 45 | return queue
|
24 | 46 |
|
25 | 47 |
|
26 | 48 | 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) |
| 49 | + ofm = __get_ofm__() |
38 | 50 |
|
39 | 51 | queue = [
|
40 | 52 | {
|
|
0 commit comments