diff options
author | Magnus Hagander | 2020-05-06 19:38:28 +0000 |
---|---|---|
committer | Magnus Hagander | 2020-05-06 19:55:21 +0000 |
commit | c560f0fba5813e8a8e19f90a01cadc4b8b291f94 (patch) | |
tree | 4aac3f15eab27cd4b71145a7ca0079b8dcdbb9bc /postgresqleu/confreg/util.py | |
parent | 472c7a106c6b28468e577da866f8e399d297fd1a (diff) |
Centralize conference notification sending
Break it out into separate functions, one for rendering a template and
one for sending from a string.
Diffstat (limited to 'postgresqleu/confreg/util.py')
-rw-r--r-- | postgresqleu/confreg/util.py | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/postgresqleu/confreg/util.py b/postgresqleu/confreg/util.py index 09baf4eb..49dbf49f 100644 --- a/postgresqleu/confreg/util.py +++ b/postgresqleu/confreg/util.py @@ -238,15 +238,13 @@ def notify_reg_confirmed(reg, updatewaitlist=True): m.registrations.add(reg) if reg.conference.notifyregs: - send_conference_mail(reg.conference, - reg.conference.notifyaddr, - "New registration", - 'confreg/mail/admin_notify_reg.txt', - { - 'reg': reg, - }, - sender=reg.conference.notifyaddr, - receivername=reg.conference.conferencename, + send_conference_notification_template( + reg.conference, + "New registration", + 'confreg/mail/admin_notify_reg.txt', + { + 'reg': reg, + }, ) send_welcome_email(reg) @@ -314,16 +312,14 @@ def cancel_registration(reg, is_unconfirmed=False, reason=None, user=None): reglog(reg, "Canceled registration", user) if reg.conference.notifyregs and not is_unconfirmed: - send_conference_mail(reg.conference, - reg.conference.notifyaddr, - "Canceled registration", - 'confreg/mail/admin_notify_cancel.txt', - { - 'reg': reg, - 'reason': reason, - }, - sender=reg.conference.notifyaddr, - receivername=reg.conference.conferencename, + send_conference_notification_template( + reg.conference, + "Canceled registration", + 'confreg/mail/admin_notify_cancel.txt', + { + 'reg': reg, + 'reason': reason, + }, ) @@ -406,3 +402,20 @@ def get_conference_or_404(urlname): timezone.activate(conference.tzname) return conference + + +def send_conference_notification(conference, subject, message): + if conference.notifyaddr: + send_simple_mail(conference.notifyaddr, + conference.notifyaddr, + subject, + message, + sendername=conference.conferencename) + + +def send_conference_notification_template(conference, subject, templatename, templateattr): + if not ((conference and conference.jinjadir) or os.path.exists(os.path.join(JINJA_TEMPLATE_ROOT, templatename))): + raise Exception("Mail template not found") + message = render_jinja_conference_template(conference, templatename, templateattr) + + send_conference_notification(conference, subject, message) |