move generating logic to dialog
This commit is contained in:
@@ -2,16 +2,21 @@ from .dialog_sources.Ui_elsa_add_table_entry import Ui_Dialog
|
||||
from src.logic.webrequest import WebRequest, BibTextTransformer
|
||||
from src import Icon
|
||||
from PyQt6 import QtWidgets
|
||||
from src.transformers.transformers import DictToTable
|
||||
from src.logic.zotero import ZoteroController
|
||||
from icecream import ic
|
||||
|
||||
zot = ZoteroController()
|
||||
dtt = DictToTable()
|
||||
|
||||
class ElsaAddEntry(QtWidgets.QDialog, Ui_Dialog):
|
||||
def __init__(self, parent=None, data=None):
|
||||
super(ElsaAddEntry, self).__init__(parent)
|
||||
self.setupUi(self)
|
||||
self.setWindowTitle("Eintrag hinzufügen")
|
||||
self.setWindowTitle("Eintrag zitieren")
|
||||
self.buttonBox.button(
|
||||
QtWidgets.QDialogButtonBox.StandardButton.Ok
|
||||
).clicked.connect(self.send)
|
||||
).clicked.connect(self.accept)
|
||||
self.buttonBox.button(
|
||||
QtWidgets.QDialogButtonBox.StandardButton.Cancel
|
||||
).clicked.connect(self.close)
|
||||
@@ -23,14 +28,30 @@ class ElsaAddEntry(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.btn_mono.clicked.connect(self.stack)
|
||||
self.btn_zs.clicked.connect(self.stack)
|
||||
self.btn_hg.clicked.connect(self.stack)
|
||||
self.make_quote.clicked.connect(self.display_data)
|
||||
self.copy_filename.clicked.connect(
|
||||
lambda: self.copy_to_clipboard(self.filename_edit)
|
||||
)
|
||||
self.copy_ilias_filename.clicked.connect(
|
||||
lambda: self.copy_to_clipboard(self.ilias_filename)
|
||||
)
|
||||
self.copy_qoute.clicked.connect(
|
||||
lambda: self.copy_to_clipboard(self.file_desc_edit)
|
||||
)
|
||||
self.setWindowIcon(Icon("edit").icon)
|
||||
self.stackedWidget.setEnabled(False)
|
||||
self.btn_hg.setChecked(False)
|
||||
self.data = None
|
||||
|
||||
def copy_to_clipboard(self, field):
|
||||
clipboard = QtWidgets.QApplication.clipboard()
|
||||
# fields are textedits
|
||||
clipboard.setText(field.toPlainText())
|
||||
def discard(self):
|
||||
for line in self.findChildren(QtWidgets.QLineEdit):
|
||||
line.clear()
|
||||
for line in self.findChildren(QtWidgets.QTextEdit):
|
||||
line.clear()
|
||||
|
||||
def stack(self):
|
||||
self.stackedWidget.setEnabled(True)
|
||||
@@ -44,8 +65,7 @@ class ElsaAddEntry(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.stackedWidget.setCurrentIndex(2)
|
||||
self.mode = "zs"
|
||||
|
||||
def send(self):
|
||||
# get all fields from the dialog
|
||||
def display_data(self):
|
||||
fields = self.findChildren(QtWidgets.QLineEdit)
|
||||
# remove all fields from the list if they do not start with the mode and _
|
||||
fields = [field for field in fields if field.objectName().startswith(self.mode)]
|
||||
@@ -57,8 +77,70 @@ class ElsaAddEntry(QtWidgets.QDialog, Ui_Dialog):
|
||||
fdata = field.text()
|
||||
data[fname] = fdata
|
||||
data["mode"] = self.mode
|
||||
self.data = data
|
||||
self.accept()
|
||||
table = dtt.transform(data)
|
||||
|
||||
if data is None:
|
||||
return
|
||||
res_key = None
|
||||
filename = None
|
||||
ilias_name = None
|
||||
if table["type"] == "zs":
|
||||
book = zot.createBook(table["isbn"])
|
||||
res_key = zot.createJournalArticle(book, table)
|
||||
ic(book)
|
||||
a_lastname = table["section_author"].split(";")[0].strip().split(",")[0]
|
||||
a_firstname = table["section_author"].split(";")[0].strip().split(",")[1]
|
||||
author = f"{a_lastname}, {a_firstname[0]}"
|
||||
year = book.date.strip() if book.date != "" else table["year"]
|
||||
chapter = table["chapter_title"].strip()
|
||||
page = table["pages"].strip()
|
||||
if len(book.creators) > 1:
|
||||
a_lastname = f"{a_lastname}_etal"
|
||||
filename = f"{a_lastname}_{year}_{chapter}_{page}_z.pdf"
|
||||
ilias_name = f"{author}. ({year}). {chapter}. S. {page}."
|
||||
elif table["type"] == "book":
|
||||
book = zot.createBook(table["signature"])
|
||||
res_key = zot.createBookSection(book, table)
|
||||
a_lastname = book.creators[0]["lastName"].strip()
|
||||
a_firstname = book.creators[0]["firstName"].strip()
|
||||
author = f"{a_lastname}, {a_firstname[0]}"
|
||||
|
||||
title = book.title.strip()
|
||||
year = book.date.strip()
|
||||
page = table["pages"].strip()
|
||||
if len(book.creators) > 1:
|
||||
a_lastname = f"{a_lastname}_etal"
|
||||
filename = f"{a_lastname}_{year}_{title}_{page}.pdf"
|
||||
ilias_name = f"{author}. ({year}). {title}. S. {page}."
|
||||
elif table["type"] == "hg":
|
||||
book = zot.createBook(table["signature"])
|
||||
res_key = zot.createHGSection(book, table)
|
||||
a_lastname = table["section_author"].split(";")[0].strip().split(",")[0]
|
||||
a_firstname = (
|
||||
table["section_author"].split(";")[0].strip().split(",")[1].strip()[0]
|
||||
)
|
||||
author = f"{a_lastname}, {a_firstname[0]}"
|
||||
editor = table["work_author"].split(";")[0].strip().split(",")[0]
|
||||
title = table["chapter_title"].strip()
|
||||
year = book.date.strip()
|
||||
page = table["pages"].strip()
|
||||
s_authors = table["section_author"].split(";")
|
||||
s_editors = table["work_author"].split(";")
|
||||
if len(s_authors) > 1:
|
||||
a_lastname = f"{a_lastname}_etal"
|
||||
author = f"{author} et al."
|
||||
if len(s_editors) > 1:
|
||||
editor = f"{editor}_etal"
|
||||
filename = f"{a_lastname}_in_{editor}_{year}_{title}_{page}.pdf"
|
||||
ilias_name = f"{author}. ({year}). {title}. S. {page}."
|
||||
citation = None
|
||||
if res_key:
|
||||
citation = zot.get_citation(res_key)
|
||||
zot.deleteItem(res_key)
|
||||
self.file_desc_edit.setText(citation)
|
||||
self.filename_edit.setText(filename.lower())
|
||||
self.ilias_filename.setText(ilias_name)
|
||||
self.stackedWidget.setCurrentIndex(3)
|
||||
|
||||
def search(self):
|
||||
param = self.searchIdent.text()
|
||||
|
||||
Reference in New Issue
Block a user