The objective of this interface is the ability to get data from an Admidio installation and use them in python. Currently Users, groups and events are integrated
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.0 KiB

6 years ago
6 years ago
  1. from admidio_python_api.exceptions import MemberNotFoundException
  2. class Group:
  3. def __init__(self, db, group_id, name, admidio):
  4. self.__c = db.cursor()
  5. self.id = group_id
  6. self.name = name
  7. self.admidio = admidio
  8. self.members = list()
  9. self.leaders = list()
  10. sql = f"""SELECT mem_usr_id, mem_leader
  11. FROM {self.admidio.prefix}_members
  12. WHERE mem_rol_id = {self.id}
  13. AND mem_end = '9999-12-31'"""
  14. self.__c.execute(sql)
  15. for row in self.__c.fetchall():
  16. try:
  17. if row[1] == 1:
  18. self.leaders.append(admidio.getMemberFromID(row[0]))
  19. else:
  20. self.members.append(admidio.getMemberFromID(row[0]))
  21. except MemberNotFoundException:
  22. print(
  23. f"Member with id {row[0]} not found, group id: {self.id}")
  24. def getAllMembers(self):
  25. """Return leaders and members in group, combined"""
  26. return self.leaders.append(self.members)