Object contact logic implemented

This commit is contained in:
2025-03-12 09:50:06 +01:00
parent 767200096f
commit e3053be72e
8 changed files with 95 additions and 43 deletions

View File

@@ -1,10 +1,14 @@
from .DbManager import DbManager
from PySide6.QtCore import QObject, Signal
import json
import mariadb
class ContactDAO:
class ContactDAO(QObject):
newObjectContactAdded = Signal(bool)
def __init__(self):
super().__init__()
#print(f"*** File: {__file__}, __init__()")
self.__con = DbManager().getConnection()
if self.__con:
@@ -18,18 +22,28 @@ class ContactDAO:
if self.__cur:
self.__cur.callproc("addContactPerson", (enc_key, json.dumps(contact),))
self.__con.commit()
self.__cur.callproc("getLastInsertId")
contact_id = self.__cur.fetchone()
self.__cur.callproc("logger",(contact_id[0], "INSERT", "addContactPerson: New Contact added",))
self.__con.commit()
return contact_id[0]
else:
return None
except mariadb.Error as e:
print("MDB: " + str(e))
except Exception as e:
print("PYT: " + str(e))
def addObjectContact(self, contact, objectid, enc_key):
try:
if self.__cur:
self.__cur.callproc("addObjectContact", (enc_key, json.dumps(contact), objectid,))
self.__con.commit()
self.__cur.callproc("logObjectContact")
self.__con.commit()
self.newObjectContactAdded.emit(True)
except mariadb.Error as e:
print("MDB (addObjectContact): " + str(e))
self.newObjectContactAdded.emit(False)
except Exception as e:
print("PYT: " + str(e))
self.newObjectContactAdded.emit(False)
def getContact(self, contact_id, enc_key = None):
try:
if self.__cur:

View File

@@ -5,6 +5,7 @@ import logging
class ContactModel(QObject):
contactIdReady = Signal(int)
objectContactAdded = Signal(bool)
__contact = None
__contact_dict = {'contact':{}}
@@ -15,6 +16,8 @@ class ContactModel(QObject):
#self.logger = logging.getLogger()
self.__conf = ConfigLoader().getConfig()
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
self.__contact_dao = ContactDAO()
self.__contact_dao.newObjectContactAdded.connect(self.objectContactAdded)
self.__data = self.__getData()
def getContacts(self):
@@ -31,6 +34,11 @@ class ContactModel(QObject):
i = ContactDAO().addContact(contact, self.__key)
self.contactIdReady.emit(i)
@Slot(dict, int)
def addObjectContact(self, contact, objectid):
ContactDAO().addObjectContact(contact, objectid, self.__key)
#self.contactIdReady.emit(i)
def __getContact(self, contact):
self.__contact = ContactDAO().getContact(contact, self.__key)
self.__getContactInfo()

View File

@@ -6,7 +6,7 @@ from ..PyqcrmFlags import PyqcrmAppliEmpyFlags
class ObjectDAO(QObject):
newObjectAdded = Signal(bool)
newObjectAdded = Signal(bool, int)
def __init__(self):
super().__init__()
@@ -15,12 +15,17 @@ class ObjectDAO(QObject):
if self.__con:
self.__cur = self.__con.cursor()
def addObject(self, new_object, new_objcontact, enc_key):
def addObject(self, new_object):
try:
if self.__cur:
self.__cur.callproc("addObject", (json.dumps(new_object), json.dumps(new_objcontact), enc_key,))
self.__cur.callproc("addObject", (json.dumps(new_object),))
self.__con.commit()
self.newObjectAdded.emit(True)
self.__cur.callproc("getLastInsertId")
object_id = self.__cur.fetchone()
self.newObjectAdded.emit(True, object_id[0])
return object_id[0]
else:
return None
except mariadb.Error as e:
self.newObjectAdded.emit(False)
print(str(e))

View File

@@ -6,7 +6,7 @@ import re
import json
class ObjectModel(QAbstractTableModel):
objectAdded = Signal(bool)
objectAdded = Signal(bool, int)
__data = None
__object_dao = None
@@ -27,13 +27,11 @@ class ObjectModel(QAbstractTableModel):
self.__object_dao.newObjectAdded.connect(self.objectAdded)
self.__getData()
@Slot(dict, list, bool)
def addObject(self, new_object, new_objcontact = None, new_contact = False):
@Slot(dict)
def addObject(self, new_object):
#print(new_object)
print(new_objcontact)
#self.__object_dao.addObject(new_object, new_objcontact, self.__key)
o = self.__object_dao.addObject(new_object)
# @Slot(str)
# def viewCriterion(self, criterion, processed = False, fired = False):
@@ -57,15 +55,16 @@ class ObjectModel(QAbstractTableModel):
@Slot(str)
def viewCriterion(self, criterion):
print(f"Criterion: {criterion}")
self.__getData(criterion)
def data(self, index, role= Qt.DisplayRole):
if role == Qt.DisplayRole:
row = self.__data[index.row()]
applicant_col = index.column() + self.__col_skip
tr = row[applicant_col] #if type(row[index.column() + 2]) is str else str(row[index.column() + 2], "utf-8")
#print(f"Data: {tr}")
# return row[index.column() + 2]
object_col = index.column() + self.__col_skip
tr = row[object_col] #if type(row[index.column() + 2]) is str else str(row[index.column() + 2], "utf-8")
if object_col > 4 and tr:
tr = re.sub("Keine Angabe ","", tr)
return tr
return None