Implement search

This commit is contained in:
Yuri Becker
2025-04-24 01:37:09 +02:00
parent 45f19d80d0
commit 76fdc880c7
14 changed files with 125 additions and 50 deletions

View File

@@ -28,9 +28,6 @@ class AddressModel(QAbstractListModel):
PyqcrmDataRoles.CITY_ROLE: b"city",
}
def setData(self):
pass
@Slot(bool, str)
def getAddresses(self, all, zipcode):
data = AddressDAO().getAddressData(all, zipcode)

View File

@@ -1,7 +1,7 @@
import uuid
from typing import List, Callable, Any
from PySide6.QtCore import QModelIndex, Qt, QAbstractTableModel, Slot
from PySide6.QtCore import QModelIndex, Qt, QAbstractTableModel, Slot, Property, Signal
from PySide6.QtQml import QJSValue
from peewee import Select
@@ -19,10 +19,12 @@ COLUMN_NAMES = ["Vorname", "Nachname", "PLZ", "Ort"]
class ApplicantModel(QAbstractTableModel):
_applicants: Select
_search_query: str = ""
search_query_changed = Signal(str)
def __init__(self) -> None:
super().__init__()
self._applicants = Applicant.select_table_data()
self._query_applicants()
def rowCount(self, /, parent=...):
return len(self._applicants)
@@ -36,6 +38,15 @@ class ApplicantModel(QAbstractTableModel):
return COLUMNS[index.column()](applicant)
return None
@Property(str, notify=search_query_changed)
def searchQuery(self):
return self._search_query
@searchQuery.setter
def searchQuery(self, value: str):
self._search_query = value
self._query_applicants()
@Slot(int, result=dict)
def applicant(self, row) -> dict:
applicant = Applicant.get_by_id(self._applicants[row].id)
@@ -68,9 +79,13 @@ class ApplicantModel(QAbstractTableModel):
applicant.email_address = values.property("emailAddress").toString() or None
applicant.salutation = values.property("salutation").toString() or None
applicant.save(force_insert=True)
self._applicants = Applicant.select_table_data()
self._query_applicants()
def headerData(self, section: int, orientation: Qt.Orientation, role: int = Qt.ItemDataRole.DisplayRole):
if role == Qt.ItemDataRole.DisplayRole:
return COLUMN_NAMES[section]
return None
def _query_applicants(self):
self._applicants = Applicant.select_table_data(self._search_query)
self.layoutChanged.emit()

View File

@@ -73,7 +73,7 @@ class BusinessModel(QAbstractTableModel):
super().__init__()
self.__business_dao = BusinessDAO()
self.__business_dao.newBusinessAdded.connect(self.__refreshView)
self.__conf = ConfigLoader().getConfig()
self.__conf = ConfigLoader().get_config()
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
self.__getData()

View File

@@ -14,7 +14,7 @@ class ContactModel(QObject):
super().__init__()
# print(f"*** File: {__file__}, __init__()")
#self.logger = logging.getLogger()
self.__conf = ConfigLoader().getConfig()
self.__conf = ConfigLoader().get_config()
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
self.__contact_dao = ContactDAO()
self.__contact_dao.newObjectContactAdded.connect(self.objectContactAdded)

View File

@@ -19,7 +19,7 @@ class EmployeeModel(QAbstractTableModel):
super().__init__()
self.__employee_dao = EmployeeDAO()
self.__employee_dao.newEmployeeAdded.connect(self.__refreshView)
self.__conf = ConfigLoader().getConfig()
self.__conf = ConfigLoader().get_config()
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
self.__getData()

View File

@@ -22,7 +22,7 @@ class ObjectModel(QAbstractTableModel):
super().__init__()
self.__object_dao = ObjectDAO()
self.__object_dao.newObjectAdded.connect(self.__refreshView)
self.__conf = ConfigLoader().getConfig()
self.__conf = ConfigLoader().get_config()
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
self.__object_dao.newObjectAdded.connect(self.objectAdded)
self.__getData()