emails werden jetzt versendet, wenn jemand jemanden einlädt oder nach einer jobübertragung bittet.

This commit is contained in:
Tim Gröger 2020-06-06 15:51:14 +02:00
parent 622bbc546f
commit 93978395e6
3 changed files with 29 additions and 7 deletions

View File

@ -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))

View File

@ -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

View File

@ -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