Add mkdocs.yml and make changes to Ui_mail_preview.py and semesterapparat_ui.ui
This commit is contained in:
@@ -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("<html>")[0]
|
||||
mail_html = mail_template.split("<html>")[1]
|
||||
mail_html = "<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()
|
||||
Reference in New Issue
Block a user