implement general data tab view
This commit is contained in:
+11
-37
@@ -1,50 +1,30 @@
|
||||
import mariadb
|
||||
from PySide6.QtWidgets import QHBoxLayout, QCheckBox
|
||||
|
||||
from data import KontorDB
|
||||
|
||||
|
||||
class KontorModelConfig:
|
||||
|
||||
def __init__(self, db_config, main_window, table_name: str):
|
||||
def __init__(self, kontor_db: KontorDB, main_window, table_name: str):
|
||||
self.header = {}
|
||||
self.filter = {}
|
||||
self.main_window = main_window
|
||||
self._table = table_name
|
||||
self._table_id = None
|
||||
self.db_conn = mariadb.connect(
|
||||
host=db_config['mariadb']['host'],
|
||||
port=db_config['mariadb']['port'],
|
||||
user=db_config['mariadb']['user'],
|
||||
password=db_config['mariadb']['password'],
|
||||
database=db_config['mariadb']['database']
|
||||
)
|
||||
self.kontor_db = kontor_db
|
||||
self.get_table_config()
|
||||
|
||||
def get_table_id(self):
|
||||
if self._table_id is not None:
|
||||
return
|
||||
cursor = self.db_conn.cursor()
|
||||
cursor.execute("SELECT id, created_date, last_modified_date FROM meta_data_table WHERE table_name=?", (self._table, ))
|
||||
rows = cursor.fetchall()
|
||||
if len(rows) == 1:
|
||||
self._table_id = rows[0][0]
|
||||
self._table_id = self.kontor_db.get_table_id(self._table)
|
||||
|
||||
def get_table_config(self):
|
||||
if self._table_id is None:
|
||||
self.get_table_id()
|
||||
cursor = self.db_conn.cursor()
|
||||
cursor.execute("SELECT column_name, column_order, column_label FROM meta_data_column WHERE table_id=? AND is_shown is true ORDER bY column_order", (self._table_id, ))
|
||||
rows = cursor.fetchall()
|
||||
self.header.clear()
|
||||
order = 0
|
||||
for (column_name, column_order, column_label) in rows:
|
||||
self.header[order] = { 'column': column_name, 'label': column_label, 'order': column_order}
|
||||
order += 1
|
||||
# print(f"retrieved {len(rows)} columns, set {len(self.header)} headers")
|
||||
cursor.execute("SELECT column_name, filter_label from meta_data_column WHERE table_id=? AND show_filter is true", (self._table_id, ))
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
self.filter[row[0]] = {'label': row[1], 'widget': None}
|
||||
# print(f"retrieved {len(rows)} filters: {self.filter}")
|
||||
self.header = self.kontor_db.get_column_meta_data(self._table_id)
|
||||
self.filter = self.kontor_db.get_filters(self._table_id)
|
||||
|
||||
def get_filter(self) -> str:
|
||||
filter_rule = ""
|
||||
@@ -61,16 +41,10 @@ class KontorModelConfig:
|
||||
# print(f"{filter_rule=}")
|
||||
return filter_rule
|
||||
|
||||
def get_statement(self) -> str:
|
||||
filter_rule = self.get_filter()
|
||||
# self.get_table_config()
|
||||
columns = ""
|
||||
for index, column in self.header.items():
|
||||
if index > 0:
|
||||
columns += ", "
|
||||
columns += column['column']
|
||||
statement = f"SELECT {columns} FROM media_file {filter_rule}"
|
||||
return statement
|
||||
def get_data(self) -> list:
|
||||
data = self.kontor_db.get_data(self._table, self.header, self.get_filter())
|
||||
print(f"KontorModelConfig.get_data: {len(data)}")
|
||||
return data
|
||||
|
||||
def get_filter_layout(self) -> QHBoxLayout:
|
||||
filter_layout = QHBoxLayout()
|
||||
|
||||
Reference in New Issue
Block a user