Browse Source

Add custom admidio db prefixes

master
Rick 6 years ago
parent
commit
8bde958828
5 changed files with 20 additions and 16 deletions
  1. +2
    -2
      README.md
  2. +10
    -8
      admidio.py
  3. +3
    -3
      event.py
  4. +3
    -2
      group.py
  5. +2
    -1
      member.py

+ 2
- 2
README.md View File

@ -19,6 +19,6 @@ It will initialise all groups and users that are in the admidio installation.
## Todo ## Todo
* [ ] Integrate custom admidio prefixes.
* [ ] Add events to the API.
* [x] Add events to the API.
* [x] Integrate custom admidio prefixes.
* [ ] Multiple admidio organisations. * [ ] Multiple admidio organisations.

+ 10
- 8
admidio.py View File

@ -10,23 +10,25 @@ from dateutil.relativedelta import relativedelta
class Admidio: class Admidio:
"""Creates the Admidio Class""" """Creates the Admidio Class"""
def __init__(self, mysql_host, mysql_user, mysql_pass, mysql_db):
def __init__(self, mysql_host, mysql_user, mysql_pass, mysql_db,
db_prefix):
self.db = MySQLdb.connect( self.db = MySQLdb.connect(
host=mysql_host, user=mysql_user, passwd=mysql_pass, db=mysql_db) host=mysql_host, user=mysql_user, passwd=mysql_pass, db=mysql_db)
self.cursor = self.db.cursor() self.cursor = self.db.cursor()
self.prefix = db_prefix
self.members = dict() self.members = dict()
self.groups = dict() self.groups = dict()
self.events = dict() self.events = dict()
self.event_confirmation_id = None self.event_confirmation_id = None
sql = "SELECT usf_id,usf_name_intern FROM `adm_user_fields`"
sql = f"SELECT usf_id,usf_name_intern FROM {self.prefix}_user_fields"
self.cursor.execute(sql) self.cursor.execute(sql)
self.userfields = dict(self.cursor.fetchall()) self.userfields = dict(self.cursor.fetchall())
# Get the id for event confirmation role. # Get the id for event confirmation role.
# So it can exclude them from Groups # So it can exclude them from Groups
sql = """SELECT cat_id
FROM adm_categories
sql = f"""SELECT cat_id
FROM {self.prefix}_categories
WHERE cat_name_intern = 'CONFIRMATION_OF_PARTICIPATION'""" WHERE cat_name_intern = 'CONFIRMATION_OF_PARTICIPATION'"""
self.cursor.execute(sql) self.cursor.execute(sql)
self.event_confirmation_id = self.cursor.fetchone()[0] self.event_confirmation_id = self.cursor.fetchone()[0]
@ -41,8 +43,8 @@ class Admidio:
def initMembers(self): def initMembers(self):
"""Initialises all members in the Admidio installation""" """Initialises all members in the Admidio installation"""
sql = """SELECT usr_id, usr_login_name, usr_password
FROM adm_users WHERE usr_valid = 1"""
sql = f"""SELECT usr_id, usr_login_name, usr_password
FROM {self.prefix}_users WHERE usr_valid = 1"""
self.cursor.execute(sql) self.cursor.execute(sql)
for row in self.cursor.fetchall(): for row in self.cursor.fetchall():
@ -54,7 +56,7 @@ class Admidio:
"""Initialises all groups in the Admidio installation""" """Initialises all groups in the Admidio installation"""
sql = f"""SELECT rol_id, rol_name, rol_description sql = f"""SELECT rol_id, rol_name, rol_description
FROM adm_roles
FROM {self.prefix}_roles
WHERE rol_valid = 1 WHERE rol_valid = 1
AND rol_cat_id != {self.event_confirmation_id}""" AND rol_cat_id != {self.event_confirmation_id}"""
self.cursor.execute(sql) self.cursor.execute(sql)
@ -71,7 +73,7 @@ class Admidio:
sql = f"""SELECT dat_id, dat_cat_id, dat_begin, dat_end, sql = f"""SELECT dat_id, dat_cat_id, dat_begin, dat_end,
dat_headline, dat_description, dat_headline, dat_description,
dat_location, dat_country, dat_rol_id dat_location, dat_country, dat_rol_id
FROM adm_dates
FROM {self.prefix}_dates
WHERE dat_begin >'{datestring}'""" WHERE dat_begin >'{datestring}'"""
self.cursor.execute(sql) self.cursor.execute(sql)


+ 3
- 3
event.py View File

@ -18,9 +18,9 @@ class Event():
self.leaders = list() self.leaders = list()
self.number_of_guests = 0 self.number_of_guests = 0
sql = ("""SELECT mem_usr_id, mem_leader, mem_count_guests
FROM adm_members"""
f""" WHERE mem_rol_id = {self.rol_id}""")
sql = f"""SELECT mem_usr_id, mem_leader, mem_count_guests
FROM {self.admidio.prefix}_members
WHERE mem_rol_id = {self.rol_id}"""
self.__c.execute(sql) self.__c.execute(sql)
for row in self.__c.fetchall(): for row in self.__c.fetchall():


+ 3
- 2
group.py View File

@ -9,8 +9,9 @@ class Group:
self.admidio = admidio self.admidio = admidio
self.members = list() self.members = list()
self.leaders = list() self.leaders = list()
sql = ("""SELECT mem_usr_id, mem_leader FROM adm_members"""
f""" WHERE mem_rol_id = {self.id}""")
sql = f"""SELECT mem_usr_id, mem_leader
FROM {self.admidio.prefix}_members
WHERE mem_rol_id = {self.id}"""
self.__c.execute(sql) self.__c.execute(sql)
for row in self.__c.fetchall(): for row in self.__c.fetchall():


+ 2
- 1
member.py View File

@ -11,7 +11,8 @@ class Member():
self.password = password self.password = password
self.userdata = dict() self.userdata = dict()
self.admidio = admidio self.admidio = admidio
sql = f"""SELECT usd_usf_id, usd_value FROM adm_user_data
sql = f"""SELECT usd_usf_id, usd_value
FROM {self.admidio.prefix}_user_data
WHERE usd_usr_id = {self.user_id!s}""" WHERE usd_usr_id = {self.user_id!s}"""
self.__c.execute(sql) self.__c.execute(sql)
for row in self.__c.fetchall(): for row in self.__c.fetchall():


Loading…
Cancel
Save