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.

81 lines
2.6 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, cat_id, 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.cat_id = cat_id
  15. self.admidio = admidio
  16. self.participants = list()
  17. self.leaders = list()
  18. self.number_of_guests = 0
  19. sql = f"""SELECT mem_usr_id, mem_leader, mem_count_guests, mem_approved
  20. FROM {self.admidio.prefix}_members
  21. WHERE mem_rol_id = {self.rol_id}
  22. AND mem_end = '9999-12-31'"""
  23. self.__c.execute(sql)
  24. for row in self.__c.fetchall():
  25. try:
  26. self.number_of_guests += row[2]
  27. # Distinguish between members that will attend, not
  28. # attend, or will maybe attend.
  29. if row[1] == 1:
  30. self.leaders.append(
  31. [row[3], self.admidio.getMemberFromID(row[0])])
  32. else:
  33. self.participants.append(
  34. [row[3], self.admidio.getMemberFromID(row[0])])
  35. except MemberNotFoundException:
  36. print(
  37. f"Member with id {row[0]} not found, group id: {self.id}")
  38. def getAllMembers(self):
  39. """Return leaders and members in group, combined"""
  40. return self.leaders + self.participants
  41. def getAllAttend(self):
  42. """Return leaders and members which actually attend"""
  43. members = list()
  44. for i in (self.leaders + self.participants):
  45. if (i[0] == 2):
  46. members.append(i)
  47. return members
  48. def getAllMaybe(self):
  49. """Return leaders and members which will maybe attend"""
  50. members = list()
  51. for i in (self.leaders + self.participants):
  52. if (i[0] == 1):
  53. members.append(i)
  54. return members
  55. def getAllNotAttend(self):
  56. """Return leaders and members which will not attend"""
  57. members = list()
  58. for i in (self.leaders + self.participants):
  59. if (i[0] == 3):
  60. members.append(i)
  61. return members
  62. def getNumberMembers(self):
  63. """Return the total number of members"""
  64. return len(self.leaders) + len(self.participants)