Refactor database message handling to support multiple messages and enhance type hints across various classes
This commit is contained in:
@@ -3,7 +3,7 @@ from PyQt6 import QtWidgets
|
||||
from .dialog_sources.reminder_ui import Ui_Erinnerung as Ui_Dialog
|
||||
from src import Icon
|
||||
import datetime as date
|
||||
|
||||
from typing import Any
|
||||
|
||||
class ReminderDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
def __init__(self, parent=None):
|
||||
@@ -13,8 +13,10 @@ class ReminderDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.setWindowTitle("Erinnerung")
|
||||
self.dateEdit.setDate(date.datetime.now())
|
||||
|
||||
def return_message(self) -> dict:
|
||||
return {
|
||||
"message": self.message_box.toPlainText(),
|
||||
"remind_at": self.dateEdit.date().toString("yyyy-MM-dd"),
|
||||
}
|
||||
def return_message(self) -> list[dict[str, Any]]:
|
||||
return [
|
||||
{
|
||||
"message": self.message_box.toPlainText(),
|
||||
"remind_at": self.dateEdit.date().toString("yyyy-MM-dd"),
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# encoding: utf-8
|
||||
import atexit
|
||||
import os
|
||||
|
||||
import time
|
||||
import sys
|
||||
import tempfile
|
||||
import webbrowser
|
||||
@@ -260,7 +260,7 @@ class Ui(Ui_Semesterapparat):
|
||||
def create_doc(self):
|
||||
log.debug("Creating document")
|
||||
# open DocumentPrintDialog
|
||||
dialog = DocumentPrintDialog(self.MainWindow)
|
||||
dialog = DocumentPrintDialog(self.MainWindow) # type: ignore
|
||||
dialog.show()
|
||||
|
||||
def checkValidInput(self):
|
||||
@@ -269,24 +269,24 @@ class Ui(Ui_Semesterapparat):
|
||||
else:
|
||||
self.check_file.setEnabled(False)
|
||||
|
||||
def setWidget(self, widget):
|
||||
def setWidget(self, widget: QtWidgets.QWidget):
|
||||
# remove all widgets from localwidget
|
||||
|
||||
self.hideWidget()
|
||||
# add widget to localwidget
|
||||
self.admin_action.layout().addWidget(widget)
|
||||
self.admin_action.layout().addWidget(widget) # type: ignore
|
||||
|
||||
def hideWidget(self):
|
||||
try:
|
||||
widgets = [
|
||||
self.admin_action.layout().itemAt(i).widget()
|
||||
for i in range(self.admin_action.layout().count())
|
||||
self.admin_action.layout().itemAt(i).widget() # type: ignore
|
||||
for i in range(self.admin_action.layout().count()) # type: ignore
|
||||
]
|
||||
except AttributeError:
|
||||
return
|
||||
for widget in widgets:
|
||||
self.admin_action.layout().removeWidget(widget)
|
||||
widget.deleteLater()
|
||||
self.admin_action.layout().removeWidget(widget) # type: ignore
|
||||
widget.deleteLater() # type: ignore
|
||||
|
||||
def adminActions(self):
|
||||
if self.select_action_box.currentText() == "Nutzer anlegen":
|
||||
@@ -302,7 +302,7 @@ class Ui(Ui_Semesterapparat):
|
||||
self.hideWidget()
|
||||
self.admin_action.setTitle("")
|
||||
|
||||
def toggleButton(self, button):
|
||||
def toggleButton(self, button: QtWidgets.QCheckBox):
|
||||
if button.isChecked():
|
||||
button.setChecked(False)
|
||||
self.validate_semester()
|
||||
@@ -317,7 +317,7 @@ class Ui(Ui_Semesterapparat):
|
||||
|
||||
def get_apparats(self):
|
||||
alist = self.db.getAllAparats(deleted=0)
|
||||
alist = natsorted(alist, key=lambda x: x[4], reverse=True)
|
||||
alist = natsorted(alist, key=lambda x: x.appnr, reverse=True)
|
||||
self.tableWidget_apparate.setRowCount(0)
|
||||
for apparat in alist:
|
||||
self.insert_apparat_into_table(apparat)
|
||||
@@ -327,15 +327,16 @@ class Ui(Ui_Semesterapparat):
|
||||
self.app_fach.clear()
|
||||
self.app_fach.addItem("")
|
||||
self.app_fach.setCurrentText("")
|
||||
self.app_fach.addItems([subject[1] for subject in self.db.getSubjects()])
|
||||
self.app_fach.addItems([subject[1] for subject in self.db.getSubjects()]) # type: ignore
|
||||
|
||||
def open_documentation(self):
|
||||
log.info("Opening Documentation")
|
||||
if not self.docu.isRunning():
|
||||
self.docu.start()
|
||||
time.sleep(5)
|
||||
webbrowser.open("http://localhost:8000")
|
||||
|
||||
def update_calendar(self, data):
|
||||
def update_calendar(self, data: list[dict[str, Any]]):
|
||||
self.calendarWidget.setMessages([data])
|
||||
self.calendarWidget.updateCells()
|
||||
|
||||
@@ -459,8 +460,7 @@ class Ui(Ui_Semesterapparat):
|
||||
else self.sem_winter.text() + " " + self.sem_year.text()
|
||||
)
|
||||
app.prof_id_adis = self.prof_id_adis.text()
|
||||
prof_id = self.db.getProfByName(prof.fullname).id
|
||||
self.add_files(prof_id)
|
||||
self.add_files()
|
||||
app.apparat_id_adis = self.apparat_id_adis.text()
|
||||
appdata = ApparatData(prof=prof, apparat=app)
|
||||
self.db.updateApparat(appdata)
|
||||
@@ -1305,7 +1305,7 @@ class Ui(Ui_Semesterapparat):
|
||||
"prof_tel": self.prof_tel_nr.text(),
|
||||
}
|
||||
|
||||
def add_files(self, prof_id=None):
|
||||
def add_files(self):
|
||||
"""
|
||||
Add Files to the associated prof in the database
|
||||
|
||||
@@ -1346,24 +1346,28 @@ class Ui(Ui_Semesterapparat):
|
||||
self.insert_apparat_into_table(apparat)
|
||||
log.info("Inserted {} apparats into table".format(len(self.apparats)))
|
||||
|
||||
def insert_apparat_into_table(self, apparat):
|
||||
def insert_apparat_into_table(self, apparat: Apparat):
|
||||
# log.debug(apparat)
|
||||
def __dauer_check(apparat):
|
||||
return "Ja" if apparat[7] == 1 else "Nein"
|
||||
def __dauer_check(apparat: Apparat):
|
||||
return "Ja" if apparat.eternal == 1 else "Nein"
|
||||
|
||||
semester = apparat[8] if apparat[8] is not None else apparat[5]
|
||||
semester = (
|
||||
apparat.extend_until
|
||||
if apparat.extend_until is not None
|
||||
else apparat.created_semester
|
||||
)
|
||||
self.tableWidget_apparate.insertRow(0)
|
||||
self.tableWidget_apparate.setItem(
|
||||
0, 0, QtWidgets.QTableWidgetItem(str(apparat[4]))
|
||||
0, 0, QtWidgets.QTableWidgetItem(str(apparat.appnr))
|
||||
)
|
||||
self.tableWidget_apparate.setItem(
|
||||
0, 1, QtWidgets.QTableWidgetItem(str(apparat[1]))
|
||||
0, 1, QtWidgets.QTableWidgetItem(str(apparat.name))
|
||||
)
|
||||
self.tableWidget_apparate.setItem(
|
||||
0,
|
||||
2,
|
||||
QtWidgets.QTableWidgetItem(
|
||||
self.db.getProfNameById(apparat[2], add_title=False)
|
||||
self.db.getProfNameById(apparat.prof_id, add_title=False)
|
||||
),
|
||||
)
|
||||
self.tableWidget_apparate.setItem(
|
||||
@@ -1375,7 +1379,7 @@ class Ui(Ui_Semesterapparat):
|
||||
0, 4, QtWidgets.QTableWidgetItem(__dauer_check(apparat))
|
||||
)
|
||||
self.tableWidget_apparate.setItem(
|
||||
0, 5, QtWidgets.QTableWidgetItem(str(apparat[13]))
|
||||
0, 5, QtWidgets.QTableWidgetItem(str(apparat.konto))
|
||||
)
|
||||
|
||||
def open_context_menu(self, position):
|
||||
@@ -1440,7 +1444,7 @@ class Ui(Ui_Semesterapparat):
|
||||
dialog = CalendarEntry(messages=messages, date=selected_date)
|
||||
# append dialog to self.frame_2
|
||||
self.calendarlayout.addWidget(dialog)
|
||||
dialog.repaintSignal.connect(lambda: self.calendarWidget.reload(selected_date))
|
||||
dialog.repaintSignal.connect(lambda: self.calendarWidget.reload(selected_date)) # type: ignore
|
||||
|
||||
def open_settings(self):
|
||||
# log.debug(settings.dict())
|
||||
@@ -1463,7 +1467,7 @@ class Ui(Ui_Semesterapparat):
|
||||
else:
|
||||
pass
|
||||
|
||||
def media_context_menu(self, position):
|
||||
def media_context_menu(self, position): # type: ignore
|
||||
menu = QtWidgets.QMenu()
|
||||
|
||||
delete_action = QtGui.QAction("Löschen")
|
||||
@@ -1475,36 +1479,36 @@ class Ui(Ui_Semesterapparat):
|
||||
|
||||
apparatmenu = menu.addMenu("Apparate")
|
||||
generalmenu = menu.addMenu("Allgemeines")
|
||||
apparatmenu.addActions(
|
||||
apparatmenu.addActions( # type: ignore
|
||||
[apparat_add_action, apparat_copy_action, apparat_move_action]
|
||||
)
|
||||
generalmenu.addActions([edit_action, delete_action, update_data_action])
|
||||
generalmenu.addActions([edit_action, delete_action, update_data_action]) # type: ignore
|
||||
# disable apparat_add_action
|
||||
apparat_add_action.setEnabled(False)
|
||||
delete_action.triggered.connect(self.delete_medium)
|
||||
edit_action.triggered.connect(self.edit_medium)
|
||||
apparat_add_action.triggered.connect(self.add_to_apparat)
|
||||
apparat_copy_action.triggered.connect(self.copy_to_apparat)
|
||||
apparat_move_action.triggered.connect(self.move_to_apparat)
|
||||
update_data_action.triggered.connect(self.update_data)
|
||||
menu.exec(self.tableWidget_apparat_media.mapToGlobal(position))
|
||||
delete_action.triggered.connect(self.delete_medium) # type: ignore
|
||||
edit_action.triggered.connect(self.edit_medium) # type: ignore
|
||||
apparat_add_action.triggered.connect(self.add_to_apparat) # type: ignore
|
||||
apparat_copy_action.triggered.connect(self.copy_to_apparat) # type: ignore
|
||||
apparat_move_action.triggered.connect(self.move_to_apparat) # type: ignore
|
||||
update_data_action.triggered.connect(self.update_data) # type: ignore
|
||||
menu.exec(self.tableWidget_apparat_media.mapToGlobal(position)) # type: ignore
|
||||
|
||||
def update_data(self):
|
||||
# TODO: use link in table, parse data and if needed, update location / signature
|
||||
pass
|
||||
|
||||
def copy_to_apparat(self):
|
||||
selected_rows = self.tableWidget_apparat_media.selectionModel().selectedRows()
|
||||
signatures = []
|
||||
selected_rows = self.tableWidget_apparat_media.selectionModel().selectedRows() # type: ignore
|
||||
signatures: list[int] = []
|
||||
for row in selected_rows:
|
||||
signature = self.tableWidget_apparat_media.item(row.row(), 1).text()
|
||||
signature = self.tableWidget_apparat_media.item(row.row(), 1).text() # type: ignore
|
||||
book_id = self.db.getBookIdBasedOnSignature(
|
||||
self.active_apparat,
|
||||
self.db.getProfId(self.profdata),
|
||||
self.db.getProfId(self.profdata), # type: ignore
|
||||
signature,
|
||||
)
|
||||
signatures.append(book_id)
|
||||
result, apparat = self.confirm_action_dialog(
|
||||
signatures.append(book_id) # type: ignore
|
||||
result, apparat = self.confirm_action_dialog( # type: ignore
|
||||
"In welchen Apparat sollen die Medien kopiert werden?"
|
||||
)
|
||||
if result == 1:
|
||||
|
||||
@@ -2,6 +2,7 @@ from PyQt6 import QtWidgets, QtCore
|
||||
from PyQt6.QtCore import QDate
|
||||
from PyQt6.QtGui import QColor, QPen
|
||||
from src.backend import Database
|
||||
from typing import Any
|
||||
import darkdetect
|
||||
import loguru
|
||||
import sys
|
||||
@@ -37,7 +38,7 @@ class MessageCalendar(QtWidgets.QCalendarWidget):
|
||||
self.messages.remove(message)
|
||||
self.updateCells()
|
||||
|
||||
def setMessages(self, messages):
|
||||
def setMessages(self, messages: list[dict[str, Any]]):
|
||||
# remove all drawn circles
|
||||
|
||||
for message in messages:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import random
|
||||
from typing import Union
|
||||
from typing import Union, Any
|
||||
|
||||
import pyqtgraph as pg
|
||||
from PyQt6 import QtWidgets
|
||||
@@ -12,8 +12,8 @@ log.add(sys.stdout)
|
||||
log.add("logs/application.log", rotation="1 MB", retention="10 days")
|
||||
|
||||
|
||||
def mergedicts(d1, d2):
|
||||
res = {}
|
||||
def mergedicts(d1: dict[str, Any], d2: dict[str, Any]):
|
||||
res: dict[str, Any] = {}
|
||||
d1_data = list(d1.items())
|
||||
d2_data = list(d2.items())
|
||||
for i in range(len(d1)):
|
||||
@@ -24,18 +24,18 @@ def mergedicts(d1, d2):
|
||||
d1_dict = dict([d1_data_slice])
|
||||
d2_dict = dict([d2_data_slice])
|
||||
# merge the dicts
|
||||
res.update(d1_dict)
|
||||
res.update(d2_dict)
|
||||
res.update(d1_dict) # type: ignore
|
||||
res.update(d2_dict) # type: ignore
|
||||
return res
|
||||
|
||||
|
||||
class DataGraph(QtWidgets.QWidget):
|
||||
def __init__(
|
||||
self,
|
||||
title,
|
||||
data=Union[dict[list, list] | dict[list[dict[str, list]]]],
|
||||
generateMissing=False,
|
||||
label=None,
|
||||
title: str,
|
||||
data=Union[dict[list, list], dict[list[dict[str, list[Any]]]]],
|
||||
generateMissing: bool = False,
|
||||
label: str = None,
|
||||
):
|
||||
super().__init__()
|
||||
log.debug(
|
||||
|
||||
Reference in New Issue
Block a user