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: ""
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
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