add AddressModel, AddressDAO class

This commit is contained in:
2024-12-06 19:00:19 +01:00
parent 5865b33c1d
commit f4bd9c296a
8 changed files with 909 additions and 846 deletions

View File

@@ -89,7 +89,19 @@ ColumnLayout
editable: true editable: true
onCurrentTextChanged: isEmptyField() onCurrentTextChanged: isEmptyField()
onEditTextChanged: isEmptyField() onEditTextChanged: isEmptyField()
model: ["test", "test2", "test3"]
model: am
delegate: Text
{
text: model.display
elide: Text.ElideRight
// width: parent.width
// height: parent.height
verticalAlignment: Text.AlignVCenter
leftPadding: 9 //@d isable-check M16
}
} }
Label Label
@@ -97,14 +109,15 @@ ColumnLayout
text: qsTr("Ort") text: qsTr("Ort")
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
} }
TextField ComboBox
{ {
property string name: "city" property string name: "city"
id: city id: city
Layout.fillWidth: true Layout.fillWidth: true
onTextChanged: isEmptyField(city) editable: true
placeholderText: "Pflichtfeld" onEditTextChanged: isEmptyField()
placeholderTextColor: "red" onCurrentTextChanged: isEmptyField()
model: ["", "MarcosDorf", "OschkarsLand"]
} }
Label Label

View File

@@ -9,7 +9,7 @@ ApplicationWindow
{ {
id: appWindow id: appWindow
width: Screen.width * .6 width: Screen.width * .6
height: Screen.height * .7 height: Screen.height * .75
visible: true visible: true
title: "PYQCRM" title: "PYQCRM"
property string confile: "" property string confile: ""

View File

@@ -29,7 +29,7 @@ CREATE TABLE `address` (
`city` varchar(500) NOT NULL, `city` varchar(500) NOT NULL,
PRIMARY KEY (`addressid`), PRIMARY KEY (`addressid`),
UNIQUE KEY `address_unique` (`city`) UNIQUE KEY `address_unique` (`city`)
) ENGINE=InnoDB AUTO_INCREMENT=7042 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@@ -70,7 +70,7 @@ CREATE TABLE `business` (
PRIMARY KEY (`businessid`), PRIMARY KEY (`businessid`),
UNIQUE KEY `customer_unique` (`email`), UNIQUE KEY `customer_unique` (`email`),
UNIQUE KEY `business_unique` (`taxno`) UNIQUE KEY `business_unique` (`taxno`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@@ -100,7 +100,7 @@ CREATE TABLE `contact` (
`contactpersonid` int(11) NOT NULL, `contactpersonid` int(11) NOT NULL,
`businessid` tinyint(1) NOT NULL DEFAULT 1, `businessid` tinyint(1) NOT NULL DEFAULT 1,
UNIQUE KEY `contact_unique` (`id`) UNIQUE KEY `contact_unique` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@@ -123,7 +123,7 @@ CREATE TABLE `contactperson` (
`birthday` date DEFAULT NULL, `birthday` date DEFAULT NULL,
`active` tinyint(1) NOT NULL DEFAULT 1, `active` tinyint(1) NOT NULL DEFAULT 1,
PRIMARY KEY (`contactpersonid`) PRIMARY KEY (`contactpersonid`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@@ -392,7 +392,7 @@ CREATE TABLE `permissions` (
`permission` varchar(50) NOT NULL, `permission` varchar(50) NOT NULL,
PRIMARY KEY (`permissionid`), PRIMARY KEY (`permissionid`),
UNIQUE KEY `berechtigungen_unique` (`permission`) UNIQUE KEY `berechtigungen_unique` (`permission`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@@ -420,7 +420,7 @@ CREATE TABLE `postcode` (
`postcode` varchar(15) NOT NULL, `postcode` varchar(15) NOT NULL,
`addressid` int(11) NOT NULL, `addressid` int(11) NOT NULL,
PRIMARY KEY (`postcodeid`) PRIMARY KEY (`postcodeid`)
) ENGINE=InnoDB AUTO_INCREMENT=8888 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@@ -435,7 +435,7 @@ CREATE TABLE `role` (
`description` varchar(50) NOT NULL, `description` varchar(50) NOT NULL,
PRIMARY KEY (`roleid`), PRIMARY KEY (`roleid`),
UNIQUE KEY `role_unique` (`description`) UNIQUE KEY `role_unique` (`description`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@@ -570,7 +570,7 @@ CREATE TABLE `users` (
`gecos` varchar(75) DEFAULT NULL, `gecos` varchar(75) DEFAULT NULL,
PRIMARY KEY (`usersid`), PRIMARY KEY (`usersid`),
UNIQUE KEY `users_unique` (`username`) UNIQUE KEY `users_unique` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --

34
lib/DB/AddressDAO.py Normal file
View File

@@ -0,0 +1,34 @@
from .DbManager import DbManager
import mariadb
import json
class AddressDAO:
def __init__(self):
self.__con = DbManager().getConnection()
self.__cur = self.__con.cursor()
def __importPlz(self):
with open("import json filepath here", "r") as plz:
postcodes = json.load(plz)
try:
for i in postcodes:
test =i["plz_name"].split(",")
for town in test:
if "u.a" in town:
town = town[:-4]
town = town.strip()
if town:
print(f"PROCESSING {i['name']} {town}")
self.__cur.callproc("addZipCodes", (i["name"], town,))
except mariadb.OperationalError as e:
print(f"Database Error: {e}")
finally:
self.__con.commit()
print("FINISHED")#
def getAddressData(self, all = True, zipcode = None):
self.__cur.callproc("getAddress", (all, zipcode,))
self.__data = self.__cur.fetchall()
return self.__data

38
lib/DB/AddressModel.py Normal file
View File

@@ -0,0 +1,38 @@
from PySide6.QtCore import QAbstractListModel, Qt, Slot, QModelIndex
from .AddressDAO import AddressDAO
class AddressModel(QAbstractListModel):
def __init__(self):
super().__init__()
self.__address_data = AddressDAO().getAddressData()
def rowCount(self, parent = QModelIndex()):
return 10
def data(self, index, role = Qt.DisplayRole):
row = index.row()
if role == Qt.DisplayRole:
data= self.__address_data[row][2]
print(type(data))
return data
@Slot(bool, str)
def getAddresses(self, all, zipcode):
data = AddressDAO().getAddressData(all, zipcode)
return data

View File

@@ -1,7 +1,7 @@
from .DbManager import DbManager from .DbManager import DbManager
import json import json
import mariadb import mariadb
import time
class BusinessDAO: class BusinessDAO:
def __init__(self): def __init__(self):
@@ -23,34 +23,6 @@ class BusinessDAO:
print(str(e)) print(str(e))
def addPlz(self):
count = 1
with open("/home/dstoppek/Downloads/georef-germany-postleitzahl.json", "r") as plz:
postcodes = json.load(plz)
try:
for i in postcodes:
test =i["plz_name"].split(",")
for town in test:
if "u.a" in town:
town = town[:-4]
town = town.strip()
if town:
print(f"PROCESSING {i['name']} {town}")
self.__cur.callproc("addZipCodes", (i["name"], town,))
#time.sleep(1)
# self.__cur.execute(f"INSERT INTO postcode(postcode, addressid) VALUE ({i["name"]}, {count})")
# count += 1
except mariadb.OperationalError as e:
print(f"Database Error: {e}")
finally:
self.__con.commit()
print("FINISHED")

View File

@@ -10,6 +10,8 @@ import rc_pyqcrm
import rc_qml import rc_qml
from lib.DB.DbManager import DbManager from lib.DB.DbManager import DbManager
from lib.DB.UserManager import UserManager from lib.DB.UserManager import UserManager
from lib.DB.AddressModel import AddressModel
# [pyqcrm] # [pyqcrm]
@@ -54,10 +56,12 @@ if __name__ == "__main__":
DbManager(dbconf) DbManager(dbconf)
bm = BusinessModel() bm = BusinessModel()
user = UserManager() user = UserManager()
am = AddressModel()
#print(con is con2) #print(con is con2)
engine.rootContext().setContextProperty("bm", bm) engine.rootContext().setContextProperty("bm", bm)
engine.rootContext().setContextProperty("am", am)
engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}") engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}")
engine.rootContext().setContextProperty("config", config) engine.rootContext().setContextProperty("config", config)
engine.rootContext().setContextProperty("loggedin_user", user) engine.rootContext().setContextProperty("loggedin_user", user)

View File

@@ -30,6 +30,8 @@
"lib/DB/UserManager.py", "lib/DB/UserManager.py",
"lib/PyqcrmFlags.py", "lib/PyqcrmFlags.py",
"lib/DB/UserDAO.py", "lib/DB/UserDAO.py",
"lib/DB/BusinessDAO.py" "lib/DB/BusinessDAO.py",
"lib/DB/AddressModel.py",
"lib/DB/AddressDAO.py"
] ]
} }