From 506206a0fb1cc382f8c6f271bcba0968f2b31686 Mon Sep 17 00:00:00 2001
From: WorldTeacher <41587052+WorldTeacher@users.noreply.github.com>
Date: Wed, 14 Feb 2024 15:50:01 +0100
Subject: [PATCH] Add mkdocs.yml and make changes to Ui_mail_preview.py and
semesterapparat_ui.ui
---
mkdocs.yml | 1 +
src/ui/dialogs/Ui_mail_preview.py | 93 ++++++++++++++++++++++++++++++-
src/ui/semesterapparat_ui.ui | 12 ++++
3 files changed, 105 insertions(+), 1 deletion(-)
create mode 100644 mkdocs.yml
diff --git a/mkdocs.yml b/mkdocs.yml
new file mode 100644
index 0000000..278a481
--- /dev/null
+++ b/mkdocs.yml
@@ -0,0 +1 @@
+site_name: SemesterapparatsManager
diff --git a/src/ui/dialogs/Ui_mail_preview.py b/src/ui/dialogs/Ui_mail_preview.py
index 2144975..4b95e50 100644
--- a/src/ui/dialogs/Ui_mail_preview.py
+++ b/src/ui/dialogs/Ui_mail_preview.py
@@ -7,10 +7,25 @@
from PyQt6 import QtCore, QtGui, QtWidgets
+import subprocess
+import tempfile
+import os
+import re
+from omegaconf import OmegaConf
+config = OmegaConf.load("config.yaml")
class Ui_eMailPreview(object):
- def setupUi(self, eMailPreview):
+
+ def setupUi(
+ self,
+ eMailPreview,
+ app_id="",
+ app_name="",
+ app_subject="",
+ prof_name="",
+ data=None,
+ ):
eMailPreview.setObjectName("eMailPreview")
eMailPreview.resize(676, 676)
self.buttonBox = QtWidgets.QDialogButtonBox(eMailPreview)
@@ -77,6 +92,20 @@ class Ui_eMailPreview(object):
self.buttonBox.accepted.connect(eMailPreview.accept) # type: ignore
self.buttonBox.rejected.connect(eMailPreview.reject) # type: ignore
QtCore.QMetaObject.connectSlotsByName(eMailPreview)
+ self._appid = app_id
+ self._appname = app_name
+ self._subject = app_subject
+ self.prof_name.setText(prof_name)
+ self._mail_data = ""
+ self._data = data
+ self.load_mail_templates()
+ self.comboBox.addItem("")
+ self.comboBox.setCurrentText("")
+ self.buttonBox.accepted.connect(self.save_mail)
+ self.comboBox.currentIndexChanged.connect(self.set_mail)
+ self.gender_female.clicked.connect(self.set_mail)
+ self.gender_male.clicked.connect(self.set_mail)
+ self.gender_non.clicked.connect(self.set_mail)
def retranslateUi(self, eMailPreview):
_translate = QtCore.QCoreApplication.translate
@@ -90,3 +119,65 @@ class Ui_eMailPreview(object):
self.gender_female.setText(_translate("eMailPreview", "W"))
self.gender_non.setText(_translate("eMailPreview", "Divers"))
self.label_6.setText(_translate("eMailPreview", "Geschlecht"))
+
+ def get_greeting(self):
+ if self.gender_male.isChecked():
+ return "Sehr geehrter Herr"
+ elif self.gender_female.isChecked():
+ return "Sehr geehrte Frau"
+ elif self.gender_non.isChecked():
+ return "Guten Tag"
+
+
+ def set_mail(self):
+ email_template = self.comboBox.currentText()
+ if email_template == "":
+ return
+ with open(f"mail_vorlagen/{email_template}", "r", encoding="utf-8") as f:
+ mail_template = f.read()
+ header = re.findall(r"Subject: (.*)", mail_template)
+ if header:
+ email_header = header[0]
+ else:
+ email_header = email_template.split(".eml")[0]
+ self.mail_header.setText(email_header)
+ self.mail_data = mail_template.split("")[0]
+ mail_html = mail_template.split("")[1]
+ mail_html = "" + mail_html
+ mail_html = mail_html.format(
+ Profname=self.prof_name.text().split(" ")[1], Appname=self._appname, AppNr=self._appid, AppSubject = self._subject,greeting = self.get_greeting()
+ )
+
+ self.mail_body.setHtml(mail_html)
+ def load_mail_templates(self):
+ mail_templates = os.listdir("mail_vorlagen")
+ mail_templates = [f for f in mail_templates if f.endswith(".eml")]
+ print(mail_templates)
+ self.comboBox.addItems(mail_templates)
+
+ def save_mail(self):
+ # create a temporary file
+ mail_header = self.mail_header.text()
+ mail_body = self.mail_body.toHtml()
+ mail = self.mail_data + mail_body
+ mail = mail.replace("Subject:", f"Subject: {mail_header}")
+ directory = config["database"]["tempdir"]
+ directory = directory.replace("~", str(os.path.expanduser("~")))
+ with tempfile.NamedTemporaryFile(
+ mode="w", delete=False, suffix=".eml", encoding="utf-8", dir=directory
+ ) as f:
+ f.write(mail)
+ self.mail_path = f.name
+ print(self.mail_path)
+ # open the file using thunderbird
+ subprocess.Popen([f"{self.mail_path}"])
+ # delete the file
+ # os.remove(self.mail_path)
+
+def launch():
+ app = QtWidgets.QApplication([])
+ eMailPreview = QtWidgets.QDialog()
+ ui = Ui_eMailPreview()
+ ui.setupUi(eMailPreview, "1","Test","Biologie","Kirchner, Alexander")
+ eMailPreview.show()
+ app.exec()
\ No newline at end of file
diff --git a/src/ui/semesterapparat_ui.ui b/src/ui/semesterapparat_ui.ui
index 1774522..a4bc69c 100644
--- a/src/ui/semesterapparat_ui.ui
+++ b/src/ui/semesterapparat_ui.ui
@@ -2833,8 +2833,15 @@
+
+
@@ -2859,6 +2866,11 @@
true
+
+
+ Dokumentation
+
+
drpdwn_app_nr