Employee and applicant frontend and backend
This commit is contained in:
@@ -8,6 +8,7 @@ class BusinessDAO(QObject):
|
||||
newBusinessAdded = Signal()
|
||||
|
||||
__cur = None
|
||||
__all_cols = None
|
||||
|
||||
def __init__(self):
|
||||
#print(f"*** File: {__file__}, init()")
|
||||
|
||||
@@ -63,6 +63,7 @@ from ..ConfigLoader import ConfigLoader
|
||||
|
||||
class BusinessModel(QAbstractTableModel):
|
||||
__visible_index = {}
|
||||
__visible_columns = None
|
||||
__col_name = ""
|
||||
__business_dao = None
|
||||
__business = None
|
||||
|
||||
@@ -1,6 +1,56 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
from .DbManager import DbManager
|
||||
import json
|
||||
import mariadb
|
||||
from PySide6.QtCore import QObject, Signal
|
||||
from ..PyqcrmFlags import PyqcrmAppliEmpyFlags
|
||||
|
||||
|
||||
class EmployeeDAO:
|
||||
class EmployeeDAO(QObject):
|
||||
newEmployeeAdded = Signal()
|
||||
|
||||
__cur = None
|
||||
__all_cols = None
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
super().__init__()
|
||||
self.__con = DbManager().getConnection()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def getEmployees(self, enc_key, criterion = "Alle", appli_emp = 0, processed = False):
|
||||
'''
|
||||
appli_emp:
|
||||
0 = applicants and employees
|
||||
1 = applicants only
|
||||
2 = employees only
|
||||
'''
|
||||
try:
|
||||
if self.__cur:
|
||||
self.__cur.callproc("getEmployeesView", (appli_emp, processed, 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))
|
||||
|
||||
def getEmployee(self, employee_id, enc_key = None):
|
||||
try:
|
||||
if self.__cur:
|
||||
self.__cur.callproc("getEmployee", (employee_id, 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))
|
||||
|
||||
def addEmployee(self, data, enc_key, employee = False):
|
||||
try:
|
||||
if self.__cur:
|
||||
self.__cur.callproc("addApplicant", (json.dumps(data), employee, enc_key,))
|
||||
self.__con.commit()
|
||||
self.newEmployeeAdded.emit()
|
||||
|
||||
except mariadb.Error as e:
|
||||
print(str(e))
|
||||
|
||||
@@ -1,6 +1,58 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal
|
||||
from .EmployeeDAO import EmployeeDAO
|
||||
from ..PyqcrmFlags import PyqcrmFlags, PyqcrmAppliEmpyFlags
|
||||
from ..ConfigLoader import ConfigLoader
|
||||
|
||||
|
||||
class EmployeeModel:
|
||||
class EmployeeModel(QAbstractTableModel):
|
||||
__data = None
|
||||
__employee_dao = None
|
||||
__visible_index = None
|
||||
__visible_columns = None
|
||||
__col_name = ""
|
||||
__employee_dao = None
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
super().__init__()
|
||||
self.__employee_dao = EmployeeDAO()
|
||||
self.__employee_dao.newEmployeeAdded.connect(self.__refreshView)
|
||||
self.__conf = ConfigLoader().getConfig()
|
||||
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
|
||||
self.__getData()
|
||||
|
||||
@Slot(dict, bool)
|
||||
def addEmployee(self, new_employee, employee = False):
|
||||
print(new_employee)
|
||||
self.__employee_dao.addEmployee(new_employee, self.__key, employee)
|
||||
|
||||
@Slot(str)
|
||||
def viewCriterion(self, criterion):
|
||||
self.__getData(criterion)
|
||||
|
||||
@Slot()
|
||||
def __refreshView(self):
|
||||
self.__getData()
|
||||
|
||||
def __getData(self, criterion = "Alle", processed = False):
|
||||
self.beginResetModel()
|
||||
rows, self.__visible_columns = self.__employee_dao.getEmployees(self.__key, criterion, 0, processed)
|
||||
self.__data = rows
|
||||
self.endResetModel()
|
||||
|
||||
def rowCount(self, parent= QModelIndex()):
|
||||
return len (self.__data)
|
||||
|
||||
def columnCount(self, parent= QModelIndex()):
|
||||
return len(self.__visible_columns) - 2
|
||||
|
||||
def data(self, index, role= Qt.DisplayRole):
|
||||
if role == Qt.DisplayRole:
|
||||
row = self.__data[index.row()]
|
||||
return row[index.column() + 2]
|
||||
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 + 2]
|
||||
return self.__col_name
|
||||
return super().headerData(section, orientation, role)
|
||||
|
||||
@@ -5,4 +5,9 @@ class PyqcrmFlags(IntFlag):
|
||||
ADMIN = 1
|
||||
USER = 2
|
||||
|
||||
class PyqcrmAppliEmpyFlags(IntFlag):
|
||||
ALL = 0
|
||||
APPLICANT = 1
|
||||
EMPLOYEE = 2
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user