Skip to content

Commit 3765337

Browse files
Don't add incorrect info to db
1 parent 61821cf commit 3765337

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

conditional/util/housing.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,12 @@
1010
from conditional.models.models import CurrentCoops
1111
from conditional.models.models import OnFloorStatusAssigned
1212

13-
from conditional import db
1413
@lru_cache(maxsize=1024)
1514
def __get_ofm__():
1615

1716
# check that everyone in onfloor has onfloorstatus
1817
onfloors = [uids['uid'][0].decode('utf-8') for uids in ldap_get_onfloor_members()]
1918

20-
# this is bad and we shouldn't do this every time
21-
for member in onfloors:
22-
if OnFloorStatusAssigned.query.filter(OnFloorStatusAssigned.uid == member).first() is None:
23-
db.session.add(OnFloorStatusAssigned(member, datetime.min))
24-
25-
db.session.flush()
26-
db.session.commit()
2719
ofm = [
2820
{
2921
'uid': m.uid,
@@ -35,6 +27,22 @@ def __get_ofm__():
3527
CurrentCoops.uid == m.uid and CurrentCoops.active
3628
).first() is not None]
3729

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+
})
45+
3846
# sort by housing points then by time in queue
3947
ofm.sort(key=lambda m: m['time'])
4048
ofm.sort(key=lambda m: m['points'], reverse=True)

0 commit comments

Comments
 (0)