add AddressModel, AddressDAO class
This commit is contained in:
@@ -89,7 +89,19 @@ ColumnLayout
|
||||
editable: true
|
||||
onCurrentTextChanged: 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
|
||||
@@ -97,14 +109,15 @@ ColumnLayout
|
||||
text: qsTr("Ort")
|
||||
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
||||
}
|
||||
TextField
|
||||
ComboBox
|
||||
{
|
||||
property string name: "city"
|
||||
id: city
|
||||
Layout.fillWidth: true
|
||||
onTextChanged: isEmptyField(city)
|
||||
placeholderText: "Pflichtfeld"
|
||||
placeholderTextColor: "red"
|
||||
editable: true
|
||||
onEditTextChanged: isEmptyField()
|
||||
onCurrentTextChanged: isEmptyField()
|
||||
model: ["", "MarcosDorf", "OschkarsLand"]
|
||||
}
|
||||
|
||||
Label
|
||||
|
||||
@@ -9,7 +9,7 @@ ApplicationWindow
|
||||
{
|
||||
id: appWindow
|
||||
width: Screen.width * .6
|
||||
height: Screen.height * .7
|
||||
height: Screen.height * .75
|
||||
visible: true
|
||||
title: "PYQCRM"
|
||||
property string confile: ""
|
||||
|
||||
@@ -29,7 +29,7 @@ CREATE TABLE `address` (
|
||||
`city` varchar(500) NOT NULL,
|
||||
PRIMARY KEY (`addressid`),
|
||||
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 */;
|
||||
|
||||
--
|
||||
@@ -70,7 +70,7 @@ CREATE TABLE `business` (
|
||||
PRIMARY KEY (`businessid`),
|
||||
UNIQUE KEY `customer_unique` (`email`),
|
||||
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 */;
|
||||
|
||||
--
|
||||
@@ -100,7 +100,7 @@ CREATE TABLE `contact` (
|
||||
`contactpersonid` int(11) NOT NULL,
|
||||
`businessid` tinyint(1) NOT NULL DEFAULT 1,
|
||||
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 */;
|
||||
|
||||
--
|
||||
@@ -123,7 +123,7 @@ CREATE TABLE `contactperson` (
|
||||
`birthday` date DEFAULT NULL,
|
||||
`active` tinyint(1) NOT NULL DEFAULT 1,
|
||||
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 */;
|
||||
|
||||
--
|
||||
@@ -392,7 +392,7 @@ CREATE TABLE `permissions` (
|
||||
`permission` varchar(50) NOT NULL,
|
||||
PRIMARY KEY (`permissionid`),
|
||||
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 */;
|
||||
|
||||
--
|
||||
@@ -420,7 +420,7 @@ CREATE TABLE `postcode` (
|
||||
`postcode` varchar(15) NOT NULL,
|
||||
`addressid` int(11) NOT NULL,
|
||||
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 */;
|
||||
|
||||
--
|
||||
@@ -435,7 +435,7 @@ CREATE TABLE `role` (
|
||||
`description` varchar(50) NOT NULL,
|
||||
PRIMARY KEY (`roleid`),
|
||||
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 */;
|
||||
|
||||
--
|
||||
@@ -570,7 +570,7 @@ CREATE TABLE `users` (
|
||||
`gecos` varchar(75) DEFAULT NULL,
|
||||
PRIMARY KEY (`usersid`),
|
||||
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 */;
|
||||
|
||||
--
|
||||
|
||||
34
lib/DB/AddressDAO.py
Normal file
34
lib/DB/AddressDAO.py
Normal 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
38
lib/DB/AddressModel.py
Normal 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from .DbManager import DbManager
|
||||
import json
|
||||
import mariadb
|
||||
import time
|
||||
|
||||
|
||||
class BusinessDAO:
|
||||
def __init__(self):
|
||||
@@ -23,34 +23,6 @@ class BusinessDAO:
|
||||
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")
|
||||
|
||||
|
||||
|
||||
|
||||
4
main.py
4
main.py
@@ -10,6 +10,8 @@ import rc_pyqcrm
|
||||
import rc_qml
|
||||
from lib.DB.DbManager import DbManager
|
||||
from lib.DB.UserManager import UserManager
|
||||
from lib.DB.AddressModel import AddressModel
|
||||
|
||||
|
||||
|
||||
# [pyqcrm]
|
||||
@@ -54,10 +56,12 @@ if __name__ == "__main__":
|
||||
DbManager(dbconf)
|
||||
bm = BusinessModel()
|
||||
user = UserManager()
|
||||
am = AddressModel()
|
||||
|
||||
#print(con is con2)
|
||||
|
||||
engine.rootContext().setContextProperty("bm", bm)
|
||||
engine.rootContext().setContextProperty("am", am)
|
||||
engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}")
|
||||
engine.rootContext().setContextProperty("config", config)
|
||||
engine.rootContext().setContextProperty("loggedin_user", user)
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
"lib/DB/UserManager.py",
|
||||
"lib/PyqcrmFlags.py",
|
||||
"lib/DB/UserDAO.py",
|
||||
"lib/DB/BusinessDAO.py"
|
||||
"lib/DB/BusinessDAO.py",
|
||||
"lib/DB/AddressModel.py",
|
||||
"lib/DB/AddressDAO.py"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user