forked from CMS/memberPlumbing
doorUpdater: Retrieve former members and remove their schedules
This commit is contained in:
parent
952852badb
commit
cf84086446
@ -9,7 +9,7 @@ from lib.hid.DoorController import ROOT, E
|
||||
class Member():
|
||||
def __init__(self, forename="", surname="", membershipWorksID="",
|
||||
middleName="", email="", phone="",
|
||||
cardholderID=None, doorAccess=[], onHold=False,
|
||||
cardholderID=None, doorAccess=[],
|
||||
credentials=set(), levels=[], extraLevels=[], schedules=[]):
|
||||
self.forename = forename
|
||||
self.surname = surname
|
||||
@ -19,19 +19,17 @@ class Member():
|
||||
self.phone = phone
|
||||
self.cardholderID = cardholderID
|
||||
self.doorAccess = doorAccess
|
||||
self.onHold = onHold
|
||||
self.credentials = credentials
|
||||
self.levels = levels
|
||||
self.schedules = schedules
|
||||
|
||||
def __repr__(self):
|
||||
def __str__(self):
|
||||
return f"""Name: {self.forename} | {self.middleName} | {self.surname}
|
||||
MembershipWorks ID: {self.membershipWorksID}
|
||||
Email: {self.email}
|
||||
Phone: {self.phone}
|
||||
Cardholder ID: {self.cardholderID}
|
||||
doorAccess: {self.doorAccess}
|
||||
On Hold? {self.onHold}
|
||||
Credentials: {self.credentials}
|
||||
Levels: {self.levels}
|
||||
Schedules: {self.schedules}
|
||||
@ -39,13 +37,12 @@ Schedules: {self.schedules}
|
||||
|
||||
|
||||
class MembershipworksMember(Member):
|
||||
def __init__(self, data):
|
||||
def __init__(self, data, formerMember=False):
|
||||
super().__init__(data["First Name"],
|
||||
data["Last Name"],
|
||||
membershipWorksID=data["Account ID"],
|
||||
email=data["Email"],
|
||||
phone=data["Phone"],
|
||||
onHold=data["Account on Hold"] != "")
|
||||
phone=data["Phone"])
|
||||
|
||||
if data["Access Card Number"] != "":
|
||||
self.credentials = set([Credential(
|
||||
@ -54,6 +51,10 @@ class MembershipworksMember(Member):
|
||||
else:
|
||||
self.credentials = set()
|
||||
|
||||
self.onHold=data["Account on Hold"] != ""
|
||||
self.limitedOperations=data['Access Permitted During Limited Operations'] == "Y"
|
||||
self.formerMember=formerMember
|
||||
|
||||
levels = {k: v for k, v in memberLevels.items() if data[k] == k}
|
||||
self.levels = list(levels.keys())
|
||||
self.schedules = list(levels.values())
|
||||
@ -68,24 +69,38 @@ class MembershipworksMember(Member):
|
||||
self.doorAccess = [
|
||||
door for door, doorData in doors.items()
|
||||
if data["Access " + doorData.access + "?"] == "Y"
|
||||
and data['Access Permitted During Limited Operations'] == "Y"
|
||||
|
||||
]
|
||||
|
||||
def to_DoorMember(self, door):
|
||||
doorLevels = [k for k, v in self.extraLevels.items() if door.name in v]
|
||||
|
||||
if door.name not in self.doorAccess or self.onHold:
|
||||
if (door.name not in self.doorAccess
|
||||
or self.onHold
|
||||
or self.formerMember
|
||||
or not self.limitedOperations):
|
||||
schedules = []
|
||||
else:
|
||||
schedules = self.schedules + doorLevels
|
||||
|
||||
dm = DoorMember(door, **self.__dict__) # this is probably terrible
|
||||
dm.levels = self.levels + doorLevels
|
||||
dm.schedules = schedules
|
||||
dm = DoorMember(door,
|
||||
forename=self.forename,
|
||||
surname=self.surname,
|
||||
membershipWorksID=self.membershipWorksID,
|
||||
email=self.email,
|
||||
phone=self.phone,
|
||||
levels=self.levels + doorLevels,
|
||||
doorAccess=self.doorAccess,
|
||||
credentials=self.credentials,
|
||||
schedules=schedules)
|
||||
|
||||
return dm
|
||||
|
||||
def __str__(self):
|
||||
return super().__str__() + f"""OnHold? {self.onHold}
|
||||
Limited Operations Access? {self.limitedOperations}
|
||||
Former Member? {self.formerMember}
|
||||
"""
|
||||
|
||||
|
||||
class DoorMember(Member):
|
||||
def __init__(self, door, *args, **kwargs):
|
||||
@ -236,12 +251,31 @@ def update_door(door, members):
|
||||
|
||||
|
||||
def main():
|
||||
memberData = membershipworks.get_members(
|
||||
['Members', 'CMS Staff', 'Misc. Access'],
|
||||
"_id,nam,phn,eml,lvl,lbl,xws,xms,xsc,xas,xfd,xac,xcf,xeh,xse,xlo")
|
||||
membershipworks_attributes = \
|
||||
"_id,nam,phn,eml,lvl,lbl,xws,xms,xsc,xas,xfd,xac,xcf,xeh,xse,xlo"
|
||||
|
||||
memberData = membershipworks.get_members(
|
||||
['Members', 'CMS Staff', 'Misc. Access'], membershipworks_attributes)
|
||||
members = [MembershipworksMember(m) for m in memberData]
|
||||
|
||||
formerMemberData = membershipworks.get_members(
|
||||
['Former Members'], membershipworks_attributes)
|
||||
formerMembers = [MembershipworksMember(m, formerMember=True)
|
||||
for m in formerMemberData]
|
||||
|
||||
for formerMember in formerMembers:
|
||||
member = next(
|
||||
(m for m in members
|
||||
if m.membershipWorksID == formerMember.membershipWorksID),
|
||||
None)
|
||||
|
||||
# member exists in another folder
|
||||
if member is not None:
|
||||
member.formerMember = True
|
||||
else: # member is only a former member
|
||||
formerMember.formerMember = True
|
||||
members.append(formerMember)
|
||||
|
||||
for door in doors.values():
|
||||
print(door.name, door.ip)
|
||||
update_door(door, members)
|
||||
|
Loading…
Reference in New Issue
Block a user