Working code. Need to populate
This commit is contained in:
66
docketModel.py
Normal file
66
docketModel.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import datetime
|
||||
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt
|
||||
from PySide6.QtGui import QColor, QFont
|
||||
from PySide6.QtSql import QSqlQuery
|
||||
|
||||
from lib.utils import query_error
|
||||
|
||||
class docketModel(QAbstractTableModel):
|
||||
entries = []
|
||||
def __init__(self, case_id:int|None = None) -> None:
|
||||
super(docketModel,self).__init__()
|
||||
if case_id == None:
|
||||
return
|
||||
query = QSqlQuery()
|
||||
query.prepare("SELECT * FROM entries WHERE case_id = :cid "
|
||||
"ORDER BY entry_id")
|
||||
q2 = QSqlQuery()
|
||||
q2.prepare("SELECT * FROM documents WHERE entry_id = :eid")
|
||||
|
||||
query.bindValue(":cid", case_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
while query.next():
|
||||
date = datetime.date.fromtimestamp(query.value(2))
|
||||
assert isinstance(date, datetime.date)
|
||||
row = [
|
||||
date.strftime("%B %-d, %Y"),
|
||||
query.value(3)
|
||||
]
|
||||
self.entries.append(row)
|
||||
q2.bindValue(":eid", query.value("entry_id"))
|
||||
if not q2.exec():
|
||||
query_error(q2)
|
||||
row = []
|
||||
while q2.next():
|
||||
row.append(q2.value('name'))
|
||||
if len(row) > 0:
|
||||
self.entries.append([None, " ".join(row)])
|
||||
return
|
||||
|
||||
def rowCount(self, parent:QModelIndex|None = None) -> int:
|
||||
return len(self.entries)
|
||||
|
||||
def columnCount(self, parent:QModelIndex|None = None) -> int:
|
||||
return 2
|
||||
|
||||
def data(self, index: QModelIndex, role:int):
|
||||
if not index.isValid():
|
||||
return ''
|
||||
if role == Qt.ItemDataRole.DisplayRole:
|
||||
return self.entries[index.row()][index.column()]
|
||||
if role == Qt.ItemDataRole.TextAlignmentRole and index.column() == 0:
|
||||
return Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTop
|
||||
return
|
||||
|
||||
|
||||
def headerData(self, section:int, orientation:Qt.Orientation, role:int):
|
||||
if orientation == Qt.Orientation.Vertical:
|
||||
return
|
||||
if role == Qt.ItemDataRole.FontRole:
|
||||
font = QFont()
|
||||
font.setBold(True)
|
||||
return font
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return
|
||||
return ['Date', 'Proceedings and Orders'][section]
|
||||
Reference in New Issue
Block a user