diff --git a/lib/ConfigLoader.py b/lib/ConfigLoader.py index f26ed9a..aae5ce6 100644 --- a/lib/ConfigLoader.py +++ b/lib/ConfigLoader.py @@ -34,6 +34,7 @@ class ConfigLoader(QObject): # print(f"In {__file__} file, __init__()") self.config_dir = user_config_dir() + '/pyqcrm' config_dir = Path(self.config_dir) + if config_dir.exists(): self.__configLoad() if self.__config: @@ -41,6 +42,7 @@ class ConfigLoader(QObject): else: config_dir.mkdir(0o750, True, True) + @Slot(dict, result= bool) def setConfig(self, app_config): # print(f"In {__file__} file, setConfig()") @@ -212,3 +214,7 @@ class ConfigLoader(QObject): self.__config['pyqcrm']['ENCRYPTION_KEY'] = enc_key self.__saveConfig() + def getKey(self): + + return self.__config['pyqcrm']['ENCRYPTION_KEY'] + diff --git a/lib/DB/BusinessDAO.py b/lib/DB/BusinessDAO.py index bf7882d..954de8b 100644 --- a/lib/DB/BusinessDAO.py +++ b/lib/DB/BusinessDAO.py @@ -16,6 +16,7 @@ class BusinessDAO(QObject): if self.__con: self.__cur = self.__con.cursor() + def getBusiness(self, enc_key, criterion = "Alle"): if self.__cur: self.__cur.callproc("getCustomerView", (enc_key, criterion,)) @@ -24,10 +25,13 @@ class BusinessDAO(QObject): else: return None, None - def addBusiness(self, data, contact_id): + + + def addBusiness(self, key, data, contact_id): try: + if self.__cur: - self.__cur.callproc("addBusiness", (json.dumps(data), contact_id)) + self.__cur.callproc("addBusiness", (key, json.dumps(data), contact_id)) self.__con.commit() self.newBusinessAdded.emit() diff --git a/lib/DB/BusinessModel.py b/lib/DB/BusinessModel.py index 120fd70..b033225 100644 --- a/lib/DB/BusinessModel.py +++ b/lib/DB/BusinessModel.py @@ -68,15 +68,22 @@ class BusinessModel(QAbstractTableModel): def __init__(self): super().__init__() +# <<<<<<< HEAD self.__business_dao = BusinessDAO() self.__business_dao.newBusinessAdded.connect(self.__refreshView) self.__conf = ConfigLoader().getConfig() self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY'] +# ======= +# self.__key = ConfigLoader().getKey() +# >>>>>>> e28c68f (AddCustomer, AddContact finished) self.__getData() + def __getData(self, criterion = "Alle"): self.beginResetModel() + rows, self.__visible_columns = self.__business_dao.getBusiness(self.__key, criterion) + self.__data = rows self.endResetModel() @@ -84,17 +91,21 @@ class BusinessModel(QAbstractTableModel): return len (self.__data) def columnCount(self, parent= QModelIndex()): - return len(self.__visible_columns) - 1 + #return len(self.__visible_columns) - 1 + return len(self.__visible_columns) + def data(self, index, role= Qt.DisplayRole): if role == Qt.DisplayRole: row = self.__data[index.row()] - return row[index.column() + 1] + #return row[index.column() + 1] + return row[index.column()] return None def headerData(self, section, orientation, role= Qt.DisplayRole): if orientation == Qt.Horizontal and role ==Qt.DisplayRole: - self.__col_name = self.__visible_columns[section + 1] + #self.__col_name = self.__visible_columns[section + 1] + self.__col_name = self.__visible_columns[section] return self.__col_name return super().headerData(section, orientation, role) @@ -122,10 +133,12 @@ class BusinessModel(QAbstractTableModel): @Slot(dict, int) def addBusiness(self, business, contact_id): - self.__business_dao.addBusiness(business, contact_id) + + BusinessDAO().addBusiness(self.__key, business, contact_id) @Slot() def __refreshView(self): + self.__getData() @Slot(dict) diff --git a/lib/DB/ContactDAO.py b/lib/DB/ContactDAO.py index 7098ba7..a091ced 100644 --- a/lib/DB/ContactDAO.py +++ b/lib/DB/ContactDAO.py @@ -13,16 +13,14 @@ class ContactDAO: def getContacts(self): print(f"*** File: {__file__}, getContacts()") - def addContact(self, contact, enc_key): + def addContact(self, key, contact): try: - if self.__cur: - self.__cur.callproc("addContactPerson", (enc_key, json.dumps(contact),)) - self.__con.commit() - self.__cur.callproc("getLastInsertId") - contact_id = self.__cur.fetchone() - return contact_id[0] - else: - return None + self.__cur.callproc("addContactPerson", (key, json.dumps(contact),)) + self.__con.commit() + self.__cur.callproc("getLastInsertId") + contact_id = self.__cur.fetchone() + return contact_id[0] + except mariadb.Error as e: print("MDB: " + str(e)) except Exception as e: diff --git a/lib/DB/ContactModel.py b/lib/DB/ContactModel.py index 0cc833c..8262c35 100644 --- a/lib/DB/ContactModel.py +++ b/lib/DB/ContactModel.py @@ -9,8 +9,13 @@ class ContactModel(QObject): super().__init__() # print(f"*** File: {__file__}, __init__()") #self.logger = logging.getLogger() + self.__conf = ConfigLoader().getConfig() self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY'] + + self.__key = ConfigLoader().getKey() + print(f"*** File: {__file__}, __init__()") + self.__data = self.__getData() def getContacts(self): @@ -24,6 +29,7 @@ class ContactModel(QObject): @Slot(dict) def addContact(self, contact): + i = ContactDAO().addContact(contact, self.__key) self.contactIdReady.emit(i)