Fixing qml connection to save business with a new contact - some
database modifications
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
from .DbManager import DbManager
|
||||
import json
|
||||
import mariadb
|
||||
from PySide6.QtCore import QObject, Signal
|
||||
|
||||
|
||||
class BusinessDAO:
|
||||
class BusinessDAO(QObject):
|
||||
newBusinessAdded = Signal()
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.__con = DbManager().getConnection()
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def getBusiness(self, criterion = "Alle"):
|
||||
self.__cur.callproc("getCustomerView", (criterion,))
|
||||
def getBusiness(self, enc_key, criterion = "Alle"):
|
||||
self.__cur.callproc("getCustomerView", (enc_key, criterion,))
|
||||
self.__all_cols = [desc[0] for desc in self.__cur.description]
|
||||
return self.__cur.fetchall(), self.__all_cols
|
||||
|
||||
@@ -17,6 +20,7 @@ class BusinessDAO:
|
||||
try:
|
||||
self.__cur.callproc("addBusiness", (json.dumps(data), contact_id))
|
||||
self.__con.commit()
|
||||
self.newBusinessAdded.emit()
|
||||
|
||||
except mariadb.Error as e:
|
||||
print(str(e))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal
|
||||
from .BusinessDAO import BusinessDAO
|
||||
from ..PyqcrmFlags import PyqcrmFlags
|
||||
from ..ConfigLoader import ConfigLoader
|
||||
|
||||
# USERS TABLE
|
||||
# CUSTOMER_COLUMN_NAMES = \
|
||||
@@ -63,14 +64,19 @@ from ..PyqcrmFlags import PyqcrmFlags
|
||||
class BusinessModel(QAbstractTableModel):
|
||||
__visible_index = {}
|
||||
__col_name = ""
|
||||
__business_dao = None
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.__business_dao = BusinessDAO()
|
||||
self.__business_dao.newBusinessAdded.connect(self.__refreshView)
|
||||
self.__conf = ConfigLoader().getConfig()
|
||||
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
|
||||
self.__getData()
|
||||
|
||||
def __getData(self, criterion = "Alle"):
|
||||
self.beginResetModel()
|
||||
rows, self.__visible_columns = BusinessDAO().getBusiness(criterion)
|
||||
rows, self.__visible_columns = self.__business_dao.getBusiness(self.__key, criterion)
|
||||
self.__data = rows
|
||||
self.endResetModel()
|
||||
|
||||
@@ -116,7 +122,10 @@ class BusinessModel(QAbstractTableModel):
|
||||
|
||||
@Slot(dict, int)
|
||||
def addBusiness(self, business, contact_id):
|
||||
BusinessDAO().addBusiness(business, contact_id)
|
||||
self.__business_dao.addBusiness(business, contact_id)
|
||||
|
||||
@Slot()
|
||||
def __refreshView(self):
|
||||
self.__getData()
|
||||
|
||||
@Slot(dict)
|
||||
|
||||
@@ -5,16 +5,16 @@ import mariadb
|
||||
|
||||
class ContactDAO:
|
||||
def __init__(self):
|
||||
print(f"*** File: {__file__}, __init__()")
|
||||
#print(f"*** File: {__file__}, __init__()")
|
||||
self.__con = DbManager().getConnection()
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def getContacts(self):
|
||||
print(f"*** File: {__file__}, getContacts()")
|
||||
|
||||
def addContact(self, contact):
|
||||
def addContact(self, contact, enc_key):
|
||||
try:
|
||||
self.__cur.callproc("addContactPerson", (json.dumps(contact),))
|
||||
self.__cur.callproc("addContactPerson", (enc_key, json.dumps(contact),))
|
||||
self.__con.commit()
|
||||
self.__cur.callproc("getLastInsertId")
|
||||
contact_id = self.__cur.fetchone()
|
||||
|
||||
@@ -1,27 +1,30 @@
|
||||
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, QObject, Signal
|
||||
from .ContactDAO import ContactDAO
|
||||
from ..ConfigLoader import ConfigLoader
|
||||
import logging
|
||||
|
||||
class ContactModel(QObject):
|
||||
contactIdReady = Signal(int)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.__conf = ConfigLoader().getConfig()
|
||||
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
|
||||
#self.logger = logging.getLogger()
|
||||
print(f"*** File: {__file__}, __init__()")
|
||||
# print(f"*** File: {__file__}, __init__()")
|
||||
self.__data = self.__getData()
|
||||
|
||||
def getContacts(self):
|
||||
print(f"*** File: {__file__}, getContacts()")
|
||||
# print(f"*** File: {__file__}, getContacts()")
|
||||
logging.debug("No debug message")
|
||||
return self.__data
|
||||
|
||||
def __getData(self):
|
||||
print(f"*** File: {__file__}, __getData()")
|
||||
# print(f"*** File: {__file__}, __getData()")
|
||||
ContactDAO().getContacts()
|
||||
|
||||
@Slot(dict)
|
||||
def addContact(self, contact):
|
||||
i = ContactDAO().addContact(contact)
|
||||
i = ContactDAO().addContact(contact, self.__key)
|
||||
self.contactIdReady.emit(i)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user