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.

104 lines
3.6 KiB

from .exceptions import MemberNotFoundException
import hashlib
class Event():
def __init__(self, event_id, rol_id, name, start_time, end_time,
description, location, country, cat_id, admidio):
self.__c = admidio.db.cursor() = event_id
self.rol_id = rol_id = name
self.start_time = start_time
self.end_time = end_time
self.description = description
self.location = location = country
self.cat_id = cat_id
self.admidio = admidio
self.participants = list()
self.leaders = list()
self.number_of_guests = 0
self.event_with_registration = False
if self.rol_id:
# Admidio only assigns a rol id when you can register for it
self.event_with_registration = True
sql = f"""SELECT mem_usr_id, mem_leader, mem_count_guests, mem_approved
FROM {self.admidio.prefix}_members
WHERE mem_rol_id = {self.rol_id}
AND mem_end = '9999-12-31'"""
for row in self.__c.fetchall():
self.number_of_guests += row[2]
# Distinguish between members that will attend, not
# attend, or will maybe attend.
if row[1] == 1:
[row[3], self.admidio.getMemberFromID(row[0])])
[row[3], self.admidio.getMemberFromID(row[0])])
except MemberNotFoundException:
"Member with id {row[0]} not found, group id:" +
def __eq__(self, other):
if isinstance(other, Event):
return self.hash() == other.hash()
def hash(self):
return hashlib.md5((str(self.rol_id)
+ self.start_time.strftime("%Y-%m-%d %H:%M:%S")
+ self.end_time.strftime("%Y-%m-%d %H:%M:%S")
+ str(
+ (''.join(str(y)
for x, y in self.participants) or '')
+ (''.join(str(y) for x, y in self.leaders) or '')
+ + (self.description or '') +
(self.location or '')
+ str(self.cat_id)).encode('utf-8')).hexdigest()
def getAllMembers(self):
"""Return leaders and members in group, combined"""
return self.leaders + self.participants
def getAllAttend(self):
"""Return leaders and members which actually attend"""
members = list()
for i in (self.leaders + self.participants):
if (i[0] == 2):
return members
def getAllMaybe(self):
"""Return leaders and members which will maybe attend"""
members = list()
for i in (self.leaders + self.participants):
if (i[0] == 1):
return members
def getAllNotAttend(self):
"""Return leaders and members which will not attend"""
members = list()
for i in (self.leaders + self.participants):
if (i[0] == 3):
return members
def getNumberMembers(self):
"""Return the total number of members"""
return len(self.leaders) + len(self.participants)