Log management wip
This commit is contained in:
parent
567a4a4e95
commit
dc4651b43a
|
|
@ -63,3 +63,4 @@ Users.register(username="USER", password="user")
|
|||
if True:
|
||||
# crud_db must be imported after db and models_reference are available
|
||||
from .crud_db import Crud_DB
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from datetime import datetime
|
|||
from pathlib import Path
|
||||
from ui.diagnostics import Diagnostics
|
||||
from lib.helpers.single_process import SingleProcess
|
||||
from ui.logs_management.info import Logs_Management
|
||||
|
||||
if platform.system().lower() == "windows":
|
||||
sys.path.append(f"{os.getcwd()}\src\components")
|
||||
|
|
@ -71,7 +72,7 @@ try:
|
|||
from lib.helpers import ConfigReader
|
||||
from PyQt5.QtCore import QObject, QThread, pyqtSignal, pyqtSlot
|
||||
from PyQt5.QtWidgets import QApplication, QMessageBox
|
||||
from ui import About, Archive, Login, Main_Window, Test, Users_Management, Recipe_Selection, \
|
||||
from ui import About, Archive, Login, Main_Window, Test, Users_Management,Logs_Management ,Recipe_Selection, \
|
||||
Barcode_Recipe_Selection
|
||||
|
||||
if "--vision" in sys.argv:
|
||||
|
|
@ -190,6 +191,8 @@ try:
|
|||
|
||||
self.main_window.about_a.triggered.connect(
|
||||
lambda checked, selfie=weakref.ref(self): selfie().main_window.open_dialog(About()))
|
||||
self.main_window.download_a.triggered.connect(
|
||||
lambda checked, selfie=weakref.ref(self): selfie().main_window.open_dialog(Logs_Management()))
|
||||
self.main_window.quit_a.triggered.connect(quit_app)
|
||||
self.main_window.users_management_a.triggered.connect(
|
||||
lambda checked, selfie=weakref.ref(self): selfie().main_window.open_dialog(Users_Management()))
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from .widget import Widget
|
|||
from .window import Window
|
||||
from .dialog import Dialog
|
||||
from .about import About
|
||||
from .logs_management import Logs_Management
|
||||
from .archive import Archive
|
||||
from .barcodes_step_editor import Barcodes_Step_Editor
|
||||
from .barcode_recipe_selection import Barcode_Recipe_Selection
|
||||
|
|
|
|||
1
src/ui/logs_management/__init__.py
Normal file
1
src/ui/logs_management/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .info import Logs_Management
|
||||
69
src/ui/logs_management/info.py
Normal file
69
src/ui/logs_management/info.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import traceback
|
||||
|
||||
from lib.db import log # Presumendo che esista un modulo per accedere alla tabella "log"
|
||||
from PyQt5.QtWidgets import QMessageBox, QTableWidget
|
||||
from ui.crud import Crud, Line_Edit_Cell_Widget
|
||||
from ui.widget import Widget
|
||||
|
||||
|
||||
class Logs_Management(Widget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
class Info_Line_Edit_Cell_Widget(Line_Edit_Cell_Widget):
|
||||
def render(self, data, row_number=None, crud=None):
|
||||
super().render(data, row_number=row_number, crud=crud)
|
||||
|
||||
def parse(self, action=None, row_number=None, crud=None):
|
||||
return self.text()
|
||||
|
||||
crud_aliases = {
|
||||
"time": "Data",
|
||||
"info_type": "Operazione",
|
||||
"info": "Info",
|
||||
}
|
||||
self.crud = Crud(
|
||||
"log",
|
||||
display_name="LOG MANAGEMENT",
|
||||
readonly=["id"],
|
||||
select=list(crud_aliases.keys()),
|
||||
fields_aliases=crud_aliases,
|
||||
autocomplete={},
|
||||
widget_classes={
|
||||
"time": Info_Line_Edit_Cell_Widget,
|
||||
"info_type": Info_Line_Edit_Cell_Widget,
|
||||
"info": Info_Line_Edit_Cell_Widget,
|
||||
},
|
||||
row_filter=self.row_filter
|
||||
)
|
||||
|
||||
self.layout().addWidget(self.crud, 0, 0, -1, -1)
|
||||
|
||||
# Adjust the column widths based on content
|
||||
self.adjust_column_widths()
|
||||
|
||||
def adjust_column_widths(self):
|
||||
"""Adjust the widths of columns to fit their content."""
|
||||
# Assuming self.crud has an attribute 'table' that is a QTableWidget or QTableView
|
||||
if hasattr(self.crud, 'table') and isinstance(self.crud.table, (QTableWidget,)):
|
||||
self.crud.table.resizeColumnsToContents()
|
||||
|
||||
def row_filter(self, row, row_number, crud):
|
||||
try:
|
||||
if row["info_type"] != "Download":
|
||||
return False, None, False
|
||||
|
||||
log_entry = log.generate(
|
||||
id=row["id"],
|
||||
time=row["time"],
|
||||
info_type=row["info_type"],
|
||||
info=row["info"]
|
||||
)
|
||||
except AssertionError as e:
|
||||
self.log.exception(traceback.format_exc())
|
||||
self.crud.set_row_color(row_number, "red")
|
||||
QMessageBox.critical(None, "Errore Salvataggio DB", f"Errore alla riga {row_number}:\n{str(e)}")
|
||||
return False, None, True
|
||||
|
||||
row.update(log_entry)
|
||||
return True, row, False
|
||||
20
src/ui/logs_management/logs_management.ui
Normal file
20
src/ui/logs_management/logs_management.ui
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Logs_Management</class>
|
||||
<widget class="QWidget" name="Users_Management">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>94</width>
|
||||
<height>18</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Logs Management</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -38,6 +38,7 @@
|
|||
<string>Informazioni</string>
|
||||
</property>
|
||||
<addaction name="about_a"/>
|
||||
<addaction name="download_a"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="admin_m">
|
||||
<property name="font">
|
||||
|
|
@ -134,6 +135,11 @@
|
|||
<string>Diagnostica</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="download_a">
|
||||
<property name="text">
|
||||
<string>Aggiornamento</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user