Added code to download files for display Added code to display the downloaded files as PDFs Got some of the sizing issues resolved for entries
90 lines
2.7 KiB
Python
90 lines
2.7 KiB
Python
import datetime
|
|
from typing import Any, cast
|
|
|
|
from PySide6.QtCore import (
|
|
QAbstractTableModel,
|
|
QDate,
|
|
QDateTime,
|
|
QModelIndex,
|
|
QPersistentModelIndex,
|
|
Qt,
|
|
)
|
|
from PySide6.QtGui import QFont
|
|
from PySide6.QtSql import QSqlQuery
|
|
|
|
from lib.utils import query_error
|
|
|
|
|
|
class docketModel(QAbstractTableModel):
|
|
entries: list[list[str | None]] = []
|
|
|
|
def __init__(self, case_id: int | None = None) -> None:
|
|
super(docketModel, self).__init__()
|
|
if case_id == None:
|
|
return
|
|
self.newCase(case_id)
|
|
return
|
|
|
|
def newCase(self, case_id: int) -> None:
|
|
self.beginResetModel()
|
|
self.entries = []
|
|
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 = query.value("date")
|
|
assert isinstance(date, QDate)
|
|
row = [date.toString("MMMM d, yyyy"), 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(f'<a href="{q2.value("url")}">{q2.value("name")}</a>')
|
|
if len(row) > 0:
|
|
self.entries.append([None, " ".join(row)])
|
|
self.endResetModel()
|
|
pass
|
|
|
|
def rowCount(
|
|
self, _: QModelIndex | QPersistentModelIndex = QModelIndex()
|
|
) -> int:
|
|
return len(self.entries)
|
|
|
|
def columnCount(
|
|
self, _: QModelIndex | QPersistentModelIndex = QModelIndex()
|
|
) -> int:
|
|
return 2
|
|
|
|
def data(
|
|
self, index: QModelIndex | QPersistentModelIndex, role: int = 0
|
|
) -> Any:
|
|
if not index.isValid():
|
|
return None
|
|
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 = 0
|
|
) -> str | None | QFont:
|
|
if orientation == Qt.Orientation.Vertical:
|
|
return None
|
|
if role == Qt.ItemDataRole.FontRole:
|
|
font = QFont()
|
|
font.setBold(True)
|
|
return font
|
|
if role != Qt.ItemDataRole.DisplayRole:
|
|
return None
|
|
return ["Date", "Proceedings and Orders"][section]
|