diff --git a/src/backend/semester.py b/src/backend/semester.py index 9185c0a..4e675ac 100644 --- a/src/backend/semester.py +++ b/src/backend/semester.py @@ -6,7 +6,7 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) # logger.add(sys.stderr, format="{time} {level} {message}", level="INFO") diff --git a/src/backend/thread_bookgrabber.py b/src/backend/thread_bookgrabber.py index 71752ba..ac6ce87 100644 --- a/src/backend/thread_bookgrabber.py +++ b/src/backend/thread_bookgrabber.py @@ -8,7 +8,9 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/bookgrabber_thread.log", rotation="1 week", enqueue=True) +logger.add( + "logs/bookgrabber_thread.log", rotation="1 week", retention="1 month", enqueue=True +) log.add( "logs/application.log", rotation="1 day", diff --git a/src/backend/threads_autoadder.py b/src/backend/threads_autoadder.py index c5cd6b6..2b60474 100644 --- a/src/backend/threads_autoadder.py +++ b/src/backend/threads_autoadder.py @@ -10,10 +10,12 @@ import sys logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) -log.add( +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) +logger.add( "logs/autoadder.log", compression="zip", + rotation="1 week", + retention="1 month", ) # logger.add(sys.stderr, format="{time} {level} {message}", level="INFO") diff --git a/src/backend/threads_availchecker.py b/src/backend/threads_availchecker.py index 4ae0e4e..51227d1 100644 --- a/src/backend/threads_availchecker.py +++ b/src/backend/threads_availchecker.py @@ -14,7 +14,7 @@ import sys logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) log.add( "logs/availthread.log", ) diff --git a/src/logic/dataclass.py b/src/logic/dataclass.py index a5a26d1..51a88e1 100644 --- a/src/logic/dataclass.py +++ b/src/logic/dataclass.py @@ -2,7 +2,7 @@ import re from dataclasses import dataclass, field from enum import Enum - +import json @dataclass class Prof: @@ -77,23 +77,19 @@ class BookData: for key, value in data.items(): setattr(self, key, value) + @property def to_dict(self): - return self.__dict__ + """Convert the dataclass to a dictionary.""" + return json.dumps(self.__dict__, ensure_ascii=False) def from_dataclass(self, dataclass): for key, value in dataclass.__dict__.items(): setattr(self, key, value) def from_string(self, data: str): - if not data.startswith("BookData"): - raise ValueError("No valid BookData string") - else: - pattern = r"(\w+)='([^']*)'" - data_dict = dict(re.findall(pattern, data)) - # print(data_dict) - for key, value in data_dict.items(): - setattr(self, key, value) - return self + data = json.loads(data) + + return BookData(**data) @dataclass diff --git a/src/logic/webrequest.py b/src/logic/webrequest.py index 998d660..3762e52 100644 --- a/src/logic/webrequest.py +++ b/src/logic/webrequest.py @@ -14,7 +14,7 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) log.add( f"logs/webrequest.log", rotation="1 day", diff --git a/src/logic/wordparser.py b/src/logic/wordparser.py index 69daa46..e4928f6 100644 --- a/src/logic/wordparser.py +++ b/src/logic/wordparser.py @@ -8,7 +8,7 @@ from typing import Union, Any logger = log logger.remove() -logger.add("logs/wordparser.log", rotation="1 week", enqueue=True) +logger.add("logs/wordparser.log", rotation="1 week", retention="1 month", enqueue=True) log.add( f"logs/application.log", rotation="1 day", diff --git a/src/transformers/transformers.py b/src/transformers/transformers.py index 765a911..151591a 100644 --- a/src/transformers/transformers.py +++ b/src/transformers/transformers.py @@ -13,7 +13,7 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) log.add( "logs/transformers.log", enqueue=True, diff --git a/src/ui/dialogs/login.py b/src/ui/dialogs/login.py index 59a5a61..0d5d184 100644 --- a/src/ui/dialogs/login.py +++ b/src/ui/dialogs/login.py @@ -13,7 +13,7 @@ from src import Icon logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) # logger.add(sys.stderr, format="{time} {level} {message}", level="INFO") diff --git a/src/ui/dialogs/mail.py b/src/ui/dialogs/mail.py index 1a42836..9491823 100644 --- a/src/ui/dialogs/mail.py +++ b/src/ui/dialogs/mail.py @@ -13,7 +13,7 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) log.add( "logs/mail.log", rotation="1 day", diff --git a/src/ui/dialogs/mailTemplate.py b/src/ui/dialogs/mailTemplate.py index b2f0ce1..7bc77b3 100644 --- a/src/ui/dialogs/mailTemplate.py +++ b/src/ui/dialogs/mailTemplate.py @@ -11,7 +11,7 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) log.add( f"logs/mail.log", enqueue=True, diff --git a/src/ui/dialogs/settings.py b/src/ui/dialogs/settings.py index f83328e..55a4695 100644 --- a/src/ui/dialogs/settings.py +++ b/src/ui/dialogs/settings.py @@ -7,7 +7,7 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) log.add( f"logs/settings.log", ) diff --git a/src/ui/widgets/MessageCalendar.py b/src/ui/widgets/MessageCalendar.py index bbc6ec8..a659440 100644 --- a/src/ui/widgets/MessageCalendar.py +++ b/src/ui/widgets/MessageCalendar.py @@ -8,7 +8,7 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) # logger.add(sys.stderr, format="{time} {level} {message}", level="INFO") diff --git a/src/ui/widgets/admin_edit_prof.py b/src/ui/widgets/admin_edit_prof.py index 1c1716c..5fe42fc 100644 --- a/src/ui/widgets/admin_edit_prof.py +++ b/src/ui/widgets/admin_edit_prof.py @@ -8,7 +8,7 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) # logger.add(sys.stderr, format="{time} {level} {message}", level="INFO") logger.add(sys.stdout) diff --git a/src/ui/widgets/admin_query.py b/src/ui/widgets/admin_query.py new file mode 100644 index 0000000..46389ee --- /dev/null +++ b/src/ui/widgets/admin_query.py @@ -0,0 +1,45 @@ +from .widget_sources.admin_query_ui import Ui_Form + +from PyQt6 import QtWidgets, QtCore +from src import Icon +from src.backend import Database + + +class AdminQueryWidget(QtWidgets.QWidget, Ui_Form): + def __init__(self, parent=None): + super().__init__(parent) + self.setupUi(self) + self.setWindowIcon(Icon("db_search").icon) + self.db = Database() + # Connect the button click to the method + self.sendquery.clicked.connect(self.on_pushButton_clicked) + + def on_pushButton_clicked(self): + # Handle button click event + self.queryResult.setRowCount(0) # Clear previous results + request_text = self.sqlquery.toPlainText() + if not request_text.strip(): + return + + data = self.db.query_db(request_text) + print(data) + table_names = ( + request_text.lower().split("select")[1].split("from")[0].split(",") + ) + table_names = [name.strip() for name in table_names] + # reset the horizontal header labels + self.queryResult.setHorizontalHeaderLabels(table_names) + for result in data: + row_position = self.queryResult.rowCount() + self.queryResult.insertRow(row_position) + for column, value in enumerate(result): + item = QtWidgets.QTableWidgetItem(str(value)) + item.setFlags(item.flags() & ~QtCore.Qt.ItemFlag.ItemIsEditable) + self.queryResult.setItem(row_position, column, item) + + +def launch(): + app = QtWidgets.QApplication([]) + widget = AdminQueryWidget() + widget.show() + app.exec() diff --git a/src/ui/widgets/elsa_main.py b/src/ui/widgets/elsa_main.py index fb5a82a..ec4f637 100644 --- a/src/ui/widgets/elsa_main.py +++ b/src/ui/widgets/elsa_main.py @@ -15,7 +15,7 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) log.add("logs/elsa_main.log", enqueue=True) logger.add(sys.stdout) diff --git a/src/ui/widgets/graph.py b/src/ui/widgets/graph.py index d21f95f..4f8987c 100644 --- a/src/ui/widgets/graph.py +++ b/src/ui/widgets/graph.py @@ -8,7 +8,7 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) log.add( "logs/graph.log", ) diff --git a/src/ui/widgets/searchPage.py b/src/ui/widgets/searchPage.py index debc557..fe0fb68 100644 --- a/src/ui/widgets/searchPage.py +++ b/src/ui/widgets/searchPage.py @@ -13,7 +13,7 @@ from loguru import logger as log logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) log.add("logs/searchPage.log", enqueue=True) # logger.add(sys.stderr, format="{time} {level} {message}", level="INFO") @@ -46,7 +46,6 @@ class SearchStatisticPage(QtWidgets.QDialog, Ui_Dialog): self.statistics_table.doubleClicked.connect(self.display_detailed_data) self.tabWidget_2.currentChanged.connect(self.tabW2_changed) self.btn_search.clicked.connect(self.statistics) - self.book_search.clicked.connect(self.search_book) self.tableWidget.customContextMenuRequested.connect( self.statistics_table_context_menu ) @@ -69,6 +68,8 @@ class SearchStatisticPage(QtWidgets.QDialog, Ui_Dialog): # set tableWidget column 0 to be 50px wide self.tableWidget.setColumnWidth(0, 50) self.semester = Semester().value + self.search_by_signature.returnPressed.connect(self.search_book) + self.search_by_title.returnPressed.connect(self.search_book) self.populate_tab() def restore_apparat(self): @@ -143,7 +144,7 @@ class SearchStatisticPage(QtWidgets.QDialog, Ui_Dialog): def search_book(self): self.book_search_result.setRowCount(0) - signature = self.seach_by_signature.text() + signature = self.search_by_signature.text() title = self.search_by_title.text() params = { "signature": signature if signature != "" else None, @@ -155,6 +156,7 @@ class SearchStatisticPage(QtWidgets.QDialog, Ui_Dialog): if retdata is None: return for book in retdata: + logger.debug(book) self.book_search_result.insertRow(0) self.book_search_result.setItem( 0, 0, QtWidgets.QTableWidgetItem(book[0].title) @@ -166,7 +168,12 @@ class SearchStatisticPage(QtWidgets.QDialog, Ui_Dialog): self.book_search_result.setItem( 0, 2, - QtWidgets.QTableWidgetItem(self.db.getApparatName(book[1], book[2])), + QtWidgets.QTableWidgetItem( + self.db.fetch_one( + "SELECT semesterapparat.appnr || ' (' || semesterapparat.name || ')' AS formatted_result from semesterapparat WHERE semesterapparat.appnr = ?", + (book[1],), + )[0], + ), ) def notify_for_deletion(self): diff --git a/src/utils/richtext.py b/src/utils/richtext.py index cc405ee..f3ba490 100644 --- a/src/utils/richtext.py +++ b/src/utils/richtext.py @@ -13,7 +13,7 @@ from src import settings logger = log logger.remove() -logger.add("logs/application.log", rotation="1 week", enqueue=True) +logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True) log.add( f"logs/{datetime.now().strftime('%Y-%m-%d')}.log", rotation="1 day",