Browse Source

Data is now actually refreshed in refresh() method

Before this commit, the MySQL connection stayed open during the whole lifetime of the Admidio object. Because of that, new data in the database could not be acquired by the refresh() method. Furthermore, the object would crash when the connection got lost.

Now, the connection is created at the start of refresh() and disconnected after refresh().
master
Dennis Potter 6 years ago
parent
commit
292b046b62
Signed by: d.potter GPG Key ID: 186A8AD440942BAF
1 changed files with 30 additions and 11 deletions
  1. +30
    -11
      admidio.py

+ 30
- 11
admidio.py View File

@ -13,14 +13,21 @@ class Admidio:
def __init__(self, mysql_host, mysql_user, mysql_pass, mysql_db,
db_prefix):
self.db = MySQLdb.connect(
host=mysql_host, user=mysql_user, passwd=mysql_pass, db=mysql_db)
self.cursor = self.db.cursor()
self.mysql_host = mysql_host
self.mysql_user = mysql_user
self.mysql_pass = mysql_pass
self.mysql_db = mysql_db
self.prefix = db_prefix
self.members = dict()
self.groups = dict()
self.events = dict()
self.event_confirmation_id = None
self.connect_db()
sql = f"SELECT usf_id,usf_name_intern FROM {self.prefix}_user_fields"
self.cursor.execute(sql)
self.userfields = dict(self.cursor.fetchall())
@ -34,25 +41,37 @@ class Admidio:
self.cursor.execute(sql)
self.event_confirmation_id = self.cursor.fetchone()[0]
self.initMembers()
self.initGroups()
self.initEvents()
self.ready = True
self.db.close()
self.refresh()
def __del__(self):
self.db.close()
pass
def connect_db(self):
self.db = MySQLdb.connect(
host=self.mysql_host,
user=self.mysql_user,
passwd=self.mysql_pass,
db=self.mysql_db)
self.cursor = self.db.cursor()
def refresh(self):
"""Refresh all users, groups and events that are stored"""
self.connect_db()
self.ready = False
self.members = dict()
self.groups = dict()
self.events = dict()
self.members.clear()
self.groups.clear()
self.events.clear()
self.initMembers()
self.initGroups()
self.initEvents()
self.ready = True
self.db.close()
def initMembers(self):
"""Initialises all members in the Admidio installation"""


Loading…
Cancel
Save