wip
This commit is contained in:
parent
353c51aa95
commit
86953df8cd
@ -1,5 +1,10 @@
|
|||||||
|
import csv
|
||||||
|
import os
|
||||||
|
import weakref
|
||||||
|
|
||||||
|
from lib.db import Archive as ArchiveDbModel
|
||||||
from lib.db import Users
|
from lib.db import Users
|
||||||
from PyQt5.QtWidgets import QAbstractItemView
|
from PyQt5.QtWidgets import QAbstractItemView, QFileDialog
|
||||||
from ui.crud import Crud, Json_External_Dialog_Cell_Widget
|
from ui.crud import Crud, Json_External_Dialog_Cell_Widget
|
||||||
from ui.helpers import replace_widget
|
from ui.helpers import replace_widget
|
||||||
from ui.widget import Widget
|
from ui.widget import Widget
|
||||||
@ -50,6 +55,7 @@ class Archive(Widget):
|
|||||||
self.crud.db_tw.setSelectionMode(QAbstractItemView.SingleSelection)
|
self.crud.db_tw.setSelectionMode(QAbstractItemView.SingleSelection)
|
||||||
self.crud.db_tw.itemSelectionChanged.connect(self.check)
|
self.crud.db_tw.itemSelectionChanged.connect(self.check)
|
||||||
self.print_b.clicked.connect(self.print_label)
|
self.print_b.clicked.connect(self.print_label)
|
||||||
|
self.export_b.clicked.connect(lambda checked, self=weakref.ref(self): self().export())
|
||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
if not self.crud.modified:
|
if not self.crud.modified:
|
||||||
@ -68,3 +74,50 @@ class Archive(Widget):
|
|||||||
self.check()
|
self.check()
|
||||||
if self.selected is not None and self.printer is not None:
|
if self.selected is not None and self.printer is not None:
|
||||||
self.printer.print_archive_label(self.selected)
|
self.printer.print_archive_label(self.selected)
|
||||||
|
|
||||||
|
def export(self, csv_path=None):
|
||||||
|
if csv_path is None:
|
||||||
|
csv_path, _ = QFileDialog.getSaveFileName(
|
||||||
|
None,
|
||||||
|
"Esportazione archivio",
|
||||||
|
"archivio.csv",
|
||||||
|
"CSV data (*.csv);;All Files (*)",
|
||||||
|
)
|
||||||
|
csv_path = str(csv_path)
|
||||||
|
if not len(csv_path):
|
||||||
|
return
|
||||||
|
if not csv_path.lower().endswith(".csv"):
|
||||||
|
csv_path += ".csv"
|
||||||
|
csv_dir = os.path.dirname(csv_path)
|
||||||
|
if len(csv_dir):
|
||||||
|
os.makedirs(csv_dir, exist_ok=True)
|
||||||
|
data = []
|
||||||
|
fieldnames = [
|
||||||
|
# "id",
|
||||||
|
"time",
|
||||||
|
"user",
|
||||||
|
"result",
|
||||||
|
"overridden",
|
||||||
|
"test_data",
|
||||||
|
"label",
|
||||||
|
# "archived",
|
||||||
|
# "uploaded",
|
||||||
|
]
|
||||||
|
for archived in list(ArchiveDbModel.select()):
|
||||||
|
exportable = {
|
||||||
|
# "id": archived.id,
|
||||||
|
"time": archived.time,
|
||||||
|
"user": archived.user,
|
||||||
|
"result": archived.result,
|
||||||
|
"overridden": archived.overridden,
|
||||||
|
"test_data": archived.test_data,
|
||||||
|
# "label": archived.label,
|
||||||
|
# "archived": archived.archived,
|
||||||
|
# "uploaded": archived.uploaded,
|
||||||
|
}
|
||||||
|
data.append(exportable)
|
||||||
|
if len(data):
|
||||||
|
with open(csv_path, "w", newline="") as f:
|
||||||
|
w = csv.DictWriter(f, fieldnames, extrasaction="ignore")
|
||||||
|
w.writeheader()
|
||||||
|
w.writerows(data)
|
||||||
|
|||||||
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>98</width>
|
<width>184</width>
|
||||||
<height>61</height>
|
<height>51</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -27,7 +27,14 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="1" column="1">
|
||||||
|
<widget class="QPushButton" name="export_b">
|
||||||
|
<property name="text">
|
||||||
|
<string>Esporta</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QWidget" name="crud_w" native="true"/>
|
<widget class="QWidget" name="crud_w" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
@ -6,6 +6,10 @@ from PyQt5.QtGui import QKeySequence
|
|||||||
from PyQt5.QtWidgets import QMessageBox, QShortcut
|
from PyQt5.QtWidgets import QMessageBox, QShortcut
|
||||||
from ui.widget import Widget
|
from ui.widget import Widget
|
||||||
|
|
||||||
|
# TESTING
|
||||||
|
login_count = 0
|
||||||
|
# /TESTING
|
||||||
|
|
||||||
|
|
||||||
class Login(Widget):
|
class Login(Widget):
|
||||||
wrong_credentials = pyqtSignal()
|
wrong_credentials = pyqtSignal()
|
||||||
@ -26,6 +30,8 @@ class Login(Widget):
|
|||||||
self.user_cb.setCurrentText("USER")
|
self.user_cb.setCurrentText("USER")
|
||||||
self.password_le.setText("user")
|
self.password_le.setText("user")
|
||||||
if "--auto-login-admin" in sys.argv or "--auto-login-user" in sys.argv or "--test" in sys.argv:
|
if "--auto-login-admin" in sys.argv or "--auto-login-user" in sys.argv or "--test" in sys.argv:
|
||||||
|
global login_count
|
||||||
|
if login_count <= 0:
|
||||||
self.test_timer = QTimer()
|
self.test_timer = QTimer()
|
||||||
self.test_timer.setSingleShot(True)
|
self.test_timer.setSingleShot(True)
|
||||||
self.test_timer.timeout.connect(self.login_b.clicked.emit)
|
self.test_timer.timeout.connect(self.login_b.clicked.emit)
|
||||||
@ -40,4 +46,8 @@ class Login(Widget):
|
|||||||
self.wrong_credentials.emit()
|
self.wrong_credentials.emit()
|
||||||
QMessageBox.critical(None, "Errore login", "Credenziali errate")
|
QMessageBox.critical(None, "Errore login", "Credenziali errate")
|
||||||
else:
|
else:
|
||||||
|
# TESTING
|
||||||
|
global login_count
|
||||||
|
login_count += 1
|
||||||
|
# /TESTING
|
||||||
self.successful_login.emit()
|
self.successful_login.emit()
|
||||||
|
|||||||
@ -368,7 +368,7 @@ class Recipe_Selection(Widget):
|
|||||||
"stampa_etichetta_abilitata",
|
"stampa_etichetta_abilitata",
|
||||||
print_template_field,
|
print_template_field,
|
||||||
]
|
]
|
||||||
for recipe in Recipes.select():
|
for recipe in list(Recipes.select()):
|
||||||
steps = recipe.get_steps_map()
|
steps = recipe.get_steps_map()
|
||||||
exportable = {
|
exportable = {
|
||||||
recipe_name_field: recipe.name,
|
recipe_name_field: recipe.name,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user