diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index e9f1521c..8c5b4650 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -697,10 +697,11 @@ class Config: self.aux_windows = {} self.hhcs = {} self.popup_windows = {} - self.db_selected = None # database the user would like to use + self.db_selected = None # database the user would like to use self.general = General() self.emails = {} self.gui_cash_stats = GUICashStats() + self.site_ids = {} # site ID list from the database added,n = 1,0 # use n to prevent infinite loop if add_missing_elements() fails somehow while added > 0 and n < 2: @@ -1390,6 +1391,12 @@ class Config: if font_size is not None: site_node.setAttribute("font_size", font_size) return + def set_site_ids(self, sites): + self.site_ids = dict(sites) + + def get_site_id(self, site): + return( self.site_ids[site] ) + def get_aux_windows(self): """Gets the list of mucked window formats in the configuration.""" return self.aux_windows.keys() diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index f1b8dd72..f8119404 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -302,6 +302,7 @@ class Database: self.saveActions = False if self.import_options['saveActions'] == False else True if self.is_connected(): + self.get_sites() self.connection.rollback() # make sure any locks taken so far are released #end def __init__ @@ -466,6 +467,15 @@ class Database: self.cursor.execute(self.sql.query['set tx level']) self.check_version(database=database, create=create) + def get_sites(self): + self.cursor.execute("SELECT name,id FROM Sites") + sites = self.cursor.fetchall() + self.config.set_site_ids(sites) + + def add_site(self, site, site_code): + self.cursor.execute("INSERT INTO Sites " + "SELECT max(id)+1, '%s', '%s' " + "FROM Sites " % (site, site_code) ) def check_version(self, database, create): self.wrongDbVersion = False