Testing logger and debug

This commit is contained in:
2024-12-10 15:28:00 +01:00
parent 6fd0c5e770
commit 8830e277ec
5 changed files with 55 additions and 8 deletions

View File

@@ -116,7 +116,7 @@ ColumnLayout
popup.height: 300 popup.height: 300
popup.y: postcode.y + 5 - (postcode.height * 2) popup.y: postcode.y + 5 - (postcode.height * 2)
currentIndex: -1 currentIndex: -1
onCurrentIndexChanged: postcode.currentIndex = city.currentIndex // onCurrentIndexChanged: postcode.currentIndex = city.currentIndex
} }
Label Label
@@ -246,10 +246,14 @@ ColumnLayout
} }
else else
{ {
console.log("Contact available")
var contact_id = 0
new_business = JsLib.addBusiness(businessGrid) new_business = JsLib.addBusiness(businessGrid)
var new_contact = JsLib.addBusiness(addContactLayout) var new_contact = JsLib.addBusiness(addContactLayout)
bm.addBusiness(new_business) // bm.setContact(new_contact, contact_id)
bm.setContact(new_contact) // bm.addBusiness(new_business, contact_id)
contact_model.getContacts()
appLoader.source = "CustomerTables.qml" appLoader.source = "CustomerTables.qml"
} }
} }

13
lib/DB/ContactDAO.py Normal file
View File

@@ -0,0 +1,13 @@
from .DbManager import DbManager
import json
import mariadb
class ContactDAO:
def __init__(self):
print(f"*** File: {__file__}, __init__()")
self.__con = DbManager().getConnection()
self.__cur = self.__con.cursor()
def getContacts(self):
print(f"*** File: {__file__}, getContacts()")

23
lib/DB/ContactModel.py Normal file
View File

@@ -0,0 +1,23 @@
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot
from .ContactDAO import ContactDAO
import logging
logger = logging.getLogger()
print(__name__)
class ContactModel:
def __init__(self):
print(f"*** File: {__file__}, __init__()")
super().__init__()
self.__data = self.__getData()
def getContacts(self):
print(f"*** File: {__file__}, getContacts()")
logger.debug("A debug message")
return self.__data
def __getData(self):
print(f"*** File: {__file__}, __getData()")
ContactDAO().getContacts()

13
main.py
View File

@@ -1,6 +1,6 @@
# This Python file uses the following encoding: utf-8 # This Python file uses the following encoding: utf-8
import sys import sys
# from pathlib import Path import logging
from PySide6.QtGui import QGuiApplication from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine from PySide6.QtQml import QQmlApplicationEngine
#from PySide6.QtCore import QResource #from PySide6.QtCore import QResource
@@ -12,7 +12,7 @@ from lib.DB.DbManager import DbManager
from lib.DB.UserManager import UserManager from lib.DB.UserManager import UserManager
from lib.DB.AddressModel import AddressModel from lib.DB.AddressModel import AddressModel
from lib.DB.BTypeModel import BTypeModel from lib.DB.BTypeModel import BTypeModel
from lib.DB.ContactModel import ContactModel
# [pyqcrm] # [pyqcrm]
@@ -26,16 +26,19 @@ from lib.DB.BTypeModel import BTypeModel
# password="" # password=""
# name="" # name=""
# type="" # type=""
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
bad_config = False bad_config = False
am = None am = None
bm = None bm = None
btm = None btm = None
contact_model = None
user = None user = None
def initializeProgram(): def initializeProgram():
# print(f"In {__file__} file, initializeProgram()") # print(f"In {__file__} file, initializeProgram()")
global am, bad_config, bm, user, btm global am, bad_config, bm, user, btm, contact_model
if not bad_config: if not bad_config:
dbconf = config.getConfig()['database'] dbconf = config.getConfig()['database']
DbManager(dbconf) DbManager(dbconf)
@@ -44,16 +47,18 @@ def initializeProgram():
user = UserManager() user = UserManager()
am = AddressModel() am = AddressModel()
btm = BTypeModel() btm = BTypeModel()
contact_model = ContactModel()
publishContext() publishContext()
def publishContext(): def publishContext():
# print(f"In {__file__} file, publishContext()") # print(f"In {__file__} file, publishContext()")
global engine, am, bad_config, bm, user, btm global engine, am, bad_config, bm, user, btm, contact_model
engine.rootContext().setContextProperty("loggedin_user", user) engine.rootContext().setContextProperty("loggedin_user", user)
engine.rootContext().setContextProperty("bm", bm) engine.rootContext().setContextProperty("bm", bm)
engine.rootContext().setContextProperty("am", am) engine.rootContext().setContextProperty("am", am)
engine.rootContext().setContextProperty("btm", btm) engine.rootContext().setContextProperty("btm", btm)
engine.rootContext().setContextProperty("contact_model", contact_model)
if __name__ == "__main__": if __name__ == "__main__":
#QResource.registerResource("rc_qml.py") #QResource.registerResource("rc_qml.py")

View File

@@ -33,6 +33,8 @@
"lib/DB/AddressDAO.py", "lib/DB/AddressDAO.py",
"lib/PyqcrmDataRoles.py", "lib/PyqcrmDataRoles.py",
"lib/DB/BTypeModel.py", "lib/DB/BTypeModel.py",
"lib/DB/BTypeDAO.py" "lib/DB/BTypeDAO.py",
"lib/DB/ContactDAO.py",
"lib/DB/ContactModel.py"
] ]
} }