fix some bugs, add mail template emit signal to update list
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
from PyQt6 import QtWidgets
|
||||
|
||||
from src import Icon, settings as config
|
||||
from src import Icon, settings as config, logger
|
||||
|
||||
|
||||
from .dialog_sources.Ui_mail_preview import Ui_eMailPreview as MailPreviewDialog
|
||||
@@ -43,13 +43,7 @@ class Mail_Dialog(QtWidgets.QDialog, MailPreviewDialog):
|
||||
default_mail="Information zum Semesterapparat",
|
||||
):
|
||||
super().__init__(parent)
|
||||
self.setupUi(
|
||||
self,
|
||||
# app_id,
|
||||
# app_name,
|
||||
# app_subject,
|
||||
# prof_name,
|
||||
)
|
||||
self.setupUi(self)
|
||||
|
||||
logger.info("Setting up mail dialog")
|
||||
self.appid = app_id
|
||||
@@ -86,7 +80,9 @@ class Mail_Dialog(QtWidgets.QDialog, MailPreviewDialog):
|
||||
logger.info("Opening new template dialog")
|
||||
# TODO: implement new mail template dialog
|
||||
dialog = MailTemplateDialog()
|
||||
dialog.updateSignal.connect(self.load_mail_templates)
|
||||
dialog.exec()
|
||||
|
||||
pass
|
||||
|
||||
def determine_signature(self):
|
||||
@@ -103,6 +99,7 @@ Tel.: 0761/682-778 | 07617682-545"""
|
||||
logger.info("Loading mail templates")
|
||||
mail_templates = os.listdir("mail_vorlagen")
|
||||
logger.info(f"Mail templates: {mail_templates}")
|
||||
self.comboBox.clear()
|
||||
for template in mail_templates:
|
||||
self.comboBox.addItem(template)
|
||||
|
||||
@@ -146,12 +143,10 @@ Tel.: 0761/682-778 | 07617682-545"""
|
||||
)
|
||||
|
||||
self.mail_body.setHtml(mail_html)
|
||||
logger.info(f"Mail template set to {email_template}")
|
||||
|
||||
def createAndSendMail(self):
|
||||
logger.info("Sending mail")
|
||||
import smtplib
|
||||
import ssl
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
@@ -193,7 +188,13 @@ Tel.: 0761/682-778 | 07617682-545"""
|
||||
self.accept()
|
||||
|
||||
|
||||
def launch_gui(app_id="", app_name="", app_subject="", prof_name="", prof_mail=""):
|
||||
def launch_gui(
|
||||
app_id="1",
|
||||
app_name="Test",
|
||||
app_subject="Test",
|
||||
prof_name="Tester, 001",
|
||||
prof_mail="alexander.kirchner@ph-freiburg.de",
|
||||
):
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
dialog = Mail_Dialog(
|
||||
app_id=app_id,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import os
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
from PyQt6.QtGui import QFont
|
||||
from PyQt6 import QtGui, QtWidgets, QtCore
|
||||
|
||||
from src import Icon
|
||||
|
||||
from .dialog_sources import NewMailTemplateDesignerDialog
|
||||
|
||||
from src import logger
|
||||
|
||||
class MailTemplateDialog(QtWidgets.QDialog, NewMailTemplateDesignerDialog):
|
||||
updateSignal = QtCore.pyqtSignal()
|
||||
def __init__(self, parent=None) -> None:
|
||||
super().__init__(parent)
|
||||
self.setupUi(self)
|
||||
@@ -37,7 +37,7 @@ class MailTemplateDialog(QtWidgets.QDialog, NewMailTemplateDesignerDialog):
|
||||
self.buttonBox.button(
|
||||
QtWidgets.QDialogButtonBox.StandardButton.Cancel
|
||||
).clicked.connect(self.closeNow)
|
||||
|
||||
logger.info("Mail template dialog setup complete")
|
||||
def save_template(self):
|
||||
# print("save triggered")
|
||||
# create a dialog to ask for the name of the template
|
||||
@@ -50,9 +50,11 @@ class MailTemplateDialog(QtWidgets.QDialog, NewMailTemplateDesignerDialog):
|
||||
dialog.setWindowIcon(Icon("save").icon)
|
||||
save = dialog.exec()
|
||||
template_name = dialog.textValue()
|
||||
logger.info("Saving template")
|
||||
if template_name != "" and save == 1:
|
||||
template = template_name + ".eml"
|
||||
if template in os.listdir("mail_vorlagen"):
|
||||
logger.error("Template already exists")
|
||||
# warning dialog
|
||||
dialog = QtWidgets.QMessageBox()
|
||||
dialog.setIcon(QtWidgets.QMessageBox.Icon.Warning)
|
||||
@@ -69,28 +71,30 @@ class MailTemplateDialog(QtWidgets.QDialog, NewMailTemplateDesignerDialog):
|
||||
ret = dialog.exec()
|
||||
if ret == QtWidgets.QMessageBox.StandardButton.No:
|
||||
return
|
||||
mail = f"""Subject: {self.subject.text()}
|
||||
mail = f"""Subject: {self.subject.text()}
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/html; charset="UTF-8"
|
||||
Content-Transfer-Encoding: 8bit
|
||||
{self.templateEdit.toHtml()}"""
|
||||
html_head = """<html>
|
||||
html_head = """<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
</head>
|
||||
"""
|
||||
mail_base = mail.split("<html>")[0]
|
||||
mail_body = mail.split("</head>")[1]
|
||||
mail = mail_base + html_head + mail_body
|
||||
mail = (
|
||||
mail.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace(""", '"')
|
||||
.replace("&", "&")
|
||||
)
|
||||
with open(f"mail_vorlagen/{template}", "w") as f:
|
||||
f.write(mail)
|
||||
self.close()
|
||||
mail_base = mail.split("<html>")[0]
|
||||
mail_body = mail.split("</head>")[1]
|
||||
mail = mail_base + html_head + mail_body
|
||||
mail = (
|
||||
mail.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace(""", '"')
|
||||
.replace("&", "&")
|
||||
)
|
||||
with open(f"mail_vorlagen/{template}", "w", encoding="utf-8") as f:
|
||||
f.write(mail)
|
||||
self.updateSignal.emit()
|
||||
self.close()
|
||||
logger.success(f"Template {template} saved successfully")
|
||||
else:
|
||||
# warning dialog
|
||||
dialog = QtWidgets.QMessageBox()
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
from PyQt6 import QtCore, QtWidgets
|
||||
|
||||
|
||||
class Ui_Dialog(object):
|
||||
|
||||
Reference in New Issue
Block a user