From 93978395e63e13ed6d7cf1f2e13cace8cb0e0598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sat, 6 Jun 2020 15:51:14 +0200 Subject: [PATCH] =?UTF-8?q?emails=20werden=20jetzt=20versendet,=20wenn=20j?= =?UTF-8?q?emand=20jemanden=20einl=C3=A4dt=20oder=20nach=20einer=20job?= =?UTF-8?q?=C3=BCbertragung=20bittet.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geruecht/controller/emailController.py | 22 +++++++++++++++---- .../mainController/mainJobInviteController.py | 6 ++++- .../mainJobRequestController.py | 8 +++++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/geruecht/controller/emailController.py b/geruecht/controller/emailController.py index 190ac07..b49b0e6 100644 --- a/geruecht/controller/emailController.py +++ b/geruecht/controller/emailController.py @@ -38,12 +38,24 @@ class EmailController(): def jobTransact(self, user, jobtransact): debug.info("create email jobtransact {{ {} }}for user {{ {} }}".format(jobtransact, user)) - date = '{}.{}.{}'.format(jobtransact['date'].day, jobtransact['date'].month, jobtransact['date'].year) - from_user = '{} {}'.format(jobtransact['from_user'].firstname, jobtransact['from_user'].lastname) - subject = 'Bardienstanfrage am {}'.format(date) + date = '{}.{}.{}'.format(jobtransact['on_date']['day'], jobtransact['on_date']['month'], jobtransact['on_date']['year']) + from_user = '{} {}'.format(jobtransact['from_user']['firstname'], jobtransact['from_user']['lastname']) + job_kind = jobtransact['job_kind'] + subject = 'Dienstanfrage am {}'.format(date) text = MIMEText( "Hallo {} {},\n" - "{} fragt, ob du am {} zum Bardienst teilnehmen willst. Beantworte die Anfrage im Userportal von Flaschengeist.".format(user.firstname, user.lastname, from_user, date), 'utf-8') + "{} fragt, ob du am {} den Dienst {} übernehmen willst.\nBeantworte die Anfrage im Userportal von Flaschengeist.".format(user.firstname, user.lastname, from_user, date, job_kind['name']), 'utf-8') + debug.debug("subject is {{ {} }}, text is {{ {} }}".format(subject, text.as_string())) + return (subject, text) + + def jobInvite(self, user, jobtransact): + debug.info("create email jobtransact {{ {} }}for user {{ {} }}".format(jobtransact, user)) + date = '{}.{}.{}'.format(jobtransact['on_date']['day'], jobtransact['on_date']['month'], jobtransact['on_date']['year']) + from_user = '{} {}'.format(jobtransact['from_user']['firstname'], jobtransact['from_user']['lastname']) + subject = 'Diensteinladung am {}'.format(date) + text = MIMEText( + "Hallo {} {},\n" + "{} fragt, ob du am {} mit Dienst haben willst.\nBeantworte die Anfrage im Userportal von Flaschengeist.".format(user.firstname, user.lastname, from_user, date), 'utf-8') debug.debug("subject is {{ {} }}, text is {{ {} }}".format(subject, text.as_string())) return (subject, text) @@ -77,6 +89,8 @@ class EmailController(): subject, text = self.credit(user) elif type == 'jobtransact': subject, text = self.jobTransact(user, jobtransact) + elif type == 'jobinvite': + subject, text = self.jobInvite(user, jobtransact) else: raise Exception("Fail to send Email. No type is set. user={}, type={} , jobtransact={}".format(user, type, jobtransact)) diff --git a/geruecht/controller/mainController/mainJobInviteController.py b/geruecht/controller/mainController/mainJobInviteController.py index 47a1ea0..ed8e50c 100644 --- a/geruecht/controller/mainController/mainJobInviteController.py +++ b/geruecht/controller/mainController/mainJobInviteController.py @@ -1,10 +1,12 @@ from datetime import date import geruecht.controller.databaseController as dc +import geruecht.controller.emailController as ec from geruecht import getDebugLogger db = dc.DatabaseController() debug = getDebugLogger() +emailController = ec.EmailController() class Base: def getJobInvites(self, from_user, to_user, date): @@ -25,7 +27,9 @@ class Base: to_user = jobInvite['to_user'] on_date = date(jobInvite['date']['year'], jobInvite['date']['month'], jobInvite['date']['day']) debug.info("set new JobInvite from_user {{ {} }}, to_user {{ {} }}, on_date {{ {} }}") - retVal.append(db.setJobInvite(from_user, to_user, on_date)) + setJobInvite = db.setJobInvite(from_user, to_user, on_date) + retVal.append(setJobInvite) + emailController.sendMail(db.getUserById(to_user['id'], False), type='jobinvite', jobtransact=setJobInvite) debug.debug("seted JobInvites are {{ {} }}".format(retVal)) return retVal diff --git a/geruecht/controller/mainController/mainJobRequestController.py b/geruecht/controller/mainController/mainJobRequestController.py index 05529a6..e31845e 100644 --- a/geruecht/controller/mainController/mainJobRequestController.py +++ b/geruecht/controller/mainController/mainJobRequestController.py @@ -1,10 +1,11 @@ from datetime import date, time, datetime - +import geruecht.controller.emailController as ec import geruecht.controller.databaseController as dc from geruecht import getDebugLogger db = dc.DatabaseController() debug = getDebugLogger() +emailController = ec.EmailController() class Base: def getJobRequests(self, from_user, to_user, date): @@ -26,7 +27,10 @@ class Base: on_date = date(jobRequest['date']['year'], jobRequest['date']['month'], jobRequest['date']['day']) job_kind = jobRequest['job_kind'] debug.info("set new JobRequest from_user {{ {} }}, to_user {{ {} }}, on_date {{ {} }}") - retVal.append(db.setJobRequest(from_user, to_user, on_date, job_kind)) + setJobRequest = db.setJobRequest(from_user, to_user, on_date, job_kind) + retVal.append(setJobRequest) + emailController.sendMail(db.getUserById(to_user['id']), type='jobtransact', jobtransact=setJobRequest) + debug.debug("seted JobRequests are {{ {} }}".format(retVal)) return retVal