Fixing ObjectAddOnContactPerson.qml conflict
This commit is contained in:
@@ -6,7 +6,7 @@ from ..PyqcrmFlags import PyqcrmAppliEmpyFlags
|
||||
|
||||
|
||||
class EmployeeDAO(QObject):
|
||||
newEmployeeAdded = Signal()
|
||||
newEmployeeAdded = Signal(bool)
|
||||
|
||||
__cur = None
|
||||
__all_cols = None
|
||||
@@ -44,7 +44,8 @@ class EmployeeDAO(QObject):
|
||||
if self.__cur:
|
||||
self.__cur.callproc("addApplicant", (json.dumps(data), applicant, enc_key,))
|
||||
self.__con.commit()
|
||||
self.newEmployeeAdded.emit()
|
||||
self.newEmployeeAdded.emit(True)
|
||||
|
||||
except mariadb.Error as e:
|
||||
print(str(e))
|
||||
self.newEmployeeAdded.emit(False)
|
||||
|
||||
@@ -2,9 +2,11 @@ from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal
|
||||
from .EmployeeDAO import EmployeeDAO
|
||||
from ..PyqcrmFlags import PyqcrmFlags, PyqcrmAppliEmpyFlags
|
||||
from ..ConfigLoader import ConfigLoader
|
||||
import re
|
||||
|
||||
|
||||
class EmployeeModel(QAbstractTableModel):
|
||||
addedNewEmployee = Signal(bool)
|
||||
__data = None
|
||||
__employee_dao = None
|
||||
__visible_index = None
|
||||
@@ -20,21 +22,25 @@ class EmployeeModel(QAbstractTableModel):
|
||||
self.__employee_dao.newEmployeeAdded.connect(self.__refreshView)
|
||||
self.__conf = ConfigLoader().getConfig()
|
||||
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
|
||||
print(self.__key)
|
||||
self.__getData()
|
||||
|
||||
@Slot(dict, bool)
|
||||
def addEmployee(self, new_employee, applicant = True):
|
||||
new_employee['worklicense'] = int(new_employee['worklicense'])
|
||||
new_employee['residencetype'] = int(new_employee['residencetype'])
|
||||
if 'worklicense' in new_employee:
|
||||
new_employee['worklicense'] = int(new_employee['worklicense'])
|
||||
new_employee['residencetype'] = int(new_employee['residencetype'])
|
||||
self.__employee_dao.addEmployee(new_employee, self.__key, applicant)
|
||||
|
||||
@Slot(str)
|
||||
def viewCriterion(self, criterion, processed = False, fired = False):
|
||||
self.__getData(criterion, processed, fired)
|
||||
|
||||
@Slot()
|
||||
def __refreshView(self):
|
||||
self.__getData()
|
||||
@Slot(bool)
|
||||
def __refreshView(self, added):
|
||||
if added:
|
||||
self.__getData()
|
||||
self.addedNewEmployee.emit(added)
|
||||
|
||||
def __getData(self, criterion = "Alle", processed = False, fired = False, every_state = True):
|
||||
self.beginResetModel()
|
||||
@@ -64,6 +70,8 @@ class EmployeeModel(QAbstractTableModel):
|
||||
tr = row[applicant_col] #if type(row[index.column() + 2]) is str else str(row[index.column() + 2], "utf-8")
|
||||
if applicant_col == 2 and self.__everyone:
|
||||
tr = 'Ja' if tr == 1 else 'Nein'
|
||||
else:
|
||||
tr = re.sub("Keine Angabe ","", tr)
|
||||
#print(f"Data: {tr}")
|
||||
# return row[index.column() + 2]
|
||||
return tr
|
||||
|
||||
37
lib/DB/ObjectDAO.py
Normal file
37
lib/DB/ObjectDAO.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from .DbManager import DbManager
|
||||
import json
|
||||
import mariadb
|
||||
from PySide6.QtCore import QObject, Signal
|
||||
from ..PyqcrmFlags import PyqcrmAppliEmpyFlags
|
||||
|
||||
|
||||
class ObjectDAO(QObject):
|
||||
newObjectAdded = Signal(bool)
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
#print(f"*** File: {__file__}, __init__()")
|
||||
self.__con = DbManager().getConnection()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def addObject(self, new_object, new_objcontact, enc_key):
|
||||
try:
|
||||
if self.__cur:
|
||||
self.__cur.callproc("addObject", (json.dumps(new_object), json.dumps(new_objcontact), enc_key,))
|
||||
self.__con.commit()
|
||||
self.newObjectAdded.emit(True)
|
||||
except mariadb.Error as e:
|
||||
self.newObjectAdded.emit(False)
|
||||
print(str(e))
|
||||
|
||||
def getObjects(self, criterion, enc_key = None):
|
||||
try:
|
||||
if self.__cur:
|
||||
self.__cur.callproc("getObjects", (criterion, enc_key,))
|
||||
self.__all_cols = [desc[0] for desc in self.__cur.description]
|
||||
return self.__cur.fetchall(), self.__all_cols
|
||||
else:
|
||||
return None, None
|
||||
except mariadb.Error as e:
|
||||
print(str(e))
|
||||
87
lib/DB/ObjectModel.py
Normal file
87
lib/DB/ObjectModel.py
Normal file
@@ -0,0 +1,87 @@
|
||||
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal
|
||||
from .ObjectDAO import ObjectDAO
|
||||
from ..PyqcrmFlags import PyqcrmFlags, PyqcrmAppliEmpyFlags
|
||||
from ..ConfigLoader import ConfigLoader
|
||||
import re
|
||||
import json
|
||||
|
||||
class ObjectModel(QAbstractTableModel):
|
||||
objectAdded = Signal(bool)
|
||||
|
||||
__data = None
|
||||
__object_dao = None
|
||||
__visible_index = None
|
||||
__visible_columns = None
|
||||
__col_name = ""
|
||||
__employee_dao = None
|
||||
__col_skip = 2
|
||||
__everyone = True
|
||||
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.__object_dao = ObjectDAO()
|
||||
self.__object_dao.newObjectAdded.connect(self.__refreshView)
|
||||
self.__conf = ConfigLoader().getConfig()
|
||||
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
|
||||
self.__object_dao.newObjectAdded.connect(self.objectAdded)
|
||||
self.__getData()
|
||||
|
||||
@Slot(dict, list, bool)
|
||||
def addObject(self, new_object, new_objcontact = None, new_contact = False):
|
||||
print(new_object)
|
||||
|
||||
print(new_objcontact)
|
||||
|
||||
self.__object_dao.addObject(new_object, new_objcontact, self.__key)
|
||||
|
||||
# @Slot(str)
|
||||
# def viewCriterion(self, criterion, processed = False, fired = False):
|
||||
# self.__getData(criterion, processed, fired)
|
||||
|
||||
@Slot()
|
||||
def __refreshView(self):
|
||||
self.__getData()
|
||||
|
||||
def __getData(self, criterion = "Alle"):
|
||||
self.beginResetModel()
|
||||
rows, self.__visible_columns = self.__object_dao.getObjects(criterion, self.__key)
|
||||
self.__data = rows
|
||||
self.endResetModel()
|
||||
|
||||
def rowCount(self, parent= QModelIndex()):
|
||||
return len (self.__data)
|
||||
|
||||
def columnCount(self, parent= QModelIndex()):
|
||||
return len(self.__visible_columns) - self.__col_skip
|
||||
|
||||
@Slot(str)
|
||||
def viewCriterion(self, 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]
|
||||
return tr
|
||||
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 + self.__col_skip]
|
||||
return self.__col_name
|
||||
return super().headerData(section, orientation, role)
|
||||
|
||||
@Slot(int)
|
||||
def onRowClicked(self, row):
|
||||
#print(self.__data)
|
||||
print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}")
|
||||
#if not self.__employee_dict['employee'] or self.__data[row][0] != self.__employee_dict['employee']['id']:
|
||||
#self.__employee = self.__employee_dao.getEmployee(self.__data[row][0], self.__key)
|
||||
#print(self.__business)
|
||||
#self.__getEmployeeInfo()
|
||||
# self.__getContactInfo()
|
||||
# print(self.__business_dict)
|
||||
Reference in New Issue
Block a user