add AddressModel, AddressDAO class
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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: ""
|
||||||
|
|||||||
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
|
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")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
4
main.py
4
main.py
@@ -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)
|
||||||
|
|||||||
@@ -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"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user