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.

80 lines
2.5 KiB

  1. from .exceptions import MemberNotFoundException
  2. class Event():
  3. def __init__(self, event_id, rol_id, name, start_time, end_time,
  4. description, location, country, admidio):
  5. self.__c = admidio.db.cursor()
  6. self.id = event_id
  7. self.rol_id = rol_id
  8. self.name = name
  9. self.start_time = start_time
  10. self.end_time = end_time
  11. self.description = description
  12. self.location = location
  13. self.country = country
  14. self.admidio = admidio
  15. self.participants = list()
  16. self.leaders = list()
  17. self.number_of_guests = 0
  18. sql = f"""SELECT mem_usr_id, mem_leader, mem_count_guests, mem_approved
  19. FROM {self.admidio.prefix}_members
  20. WHERE mem_rol_id = {self.rol_id}
  21. AND mem_end = '9999-12-31'"""
  22. self.__c.execute(sql)
  23. for row in self.__c.fetchall():
  24. try:
  25. self.number_of_guests += row[2]
  26. # Distinguish between members that will attend, not
  27. # attend, or will maybe attend.
  28. if row[1] == 1:
  29. self.leaders.append(
  30. [row[3], self.admidio.getMemberFromID(row[0])])
  31. else:
  32. self.participants.append(
  33. [row[3], self.admidio.getMemberFromID(row[0])])
  34. except MemberNotFoundException:
  35. print(
  36. f"Member with id {row[0]} not found, group id: {self.id}")
  37. def getAllMembers(self):
  38. """Return leaders and members in group, combined"""
  39. return self.leaders + self.participants
  40. def getAllAttend(self):
  41. """Return leaders and members which actually attend"""
  42. members = list()
  43. for i in (self.leaders + self.participants):
  44. if (i[0] == 2):
  45. members.append(i)
  46. return members
  47. def getAllMaybe(self):
  48. """Return leaders and members which will maybe attend"""
  49. members = list()
  50. for i in (self.leaders + self.participants):
  51. if (i[0] == 1):
  52. members.append(i)
  53. return members
  54. def getAllNotAttend(self):
  55. """Return leaders and members which will not attend"""
  56. members = list()
  57. for i in (self.leaders + self.participants):
  58. if (i[0] == 3):
  59. members.append(i)
  60. return members
  61. def getNumberMembers(self):
  62. """Return the total number of members"""
  63. return len(self.leaders) + len(self.participants)