[Mpuls-commits] r6126 - base/trunk/mpulsweb/controllers
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Tue Oct 16 16:53:30 CEST 2012
Author: roland
Date: 2012-10-16 16:53:30 +0200 (Tue, 16 Oct 2012)
New Revision: 6126
Modified:
base/trunk/mpulsweb/controllers/settings.py
Log:
Add function to send emails on job percentage changes
This can be called from the pre-save hook on applications that use the case
key (Fallschluessel)
Modified: base/trunk/mpulsweb/controllers/settings.py
===================================================================
--- base/trunk/mpulsweb/controllers/settings.py 2012-10-16 14:51:27 UTC (rev 6125)
+++ base/trunk/mpulsweb/controllers/settings.py 2012-10-16 14:53:30 UTC (rev 6126)
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import logging
import formencode
+from subprocess import Popen, PIPE
+from email.mime.text import MIMEText
from pylons import request, tmpl_context as c, app_globals as g
from mpulsweb.lib.translation import _
@@ -88,4 +90,39 @@
pass
+
+ def send_job_percentage_email(self, form_data):
+ """
+ Sends an email if the value of the job percentage was changed
+ """
+
+ # If the job_percentage is enabled, send an email each time the value
+ # is saved and changed
+ if g.mpuls_config.is_enabled('job_percentage', 'enabled'):
+ old_value = c.agency.getJobPercentage()
+ new_value = form_data['job_percentage']
+
+ if str(old_value) != str(new_value):
+
+ # Prepare the contents of the email
+ from_adress = g.mpuls_config.get('job_percentage', 'from_email')
+ to_adress = g.mpuls_config.get('job_percentage', 'to_email')
+ message_text = _("The job percentage changed on agency %(agency)s "
+ "from %(old)s to %(new)s"
+ )% {'agency': c.agency.getName(),
+ 'old': old_value,
+ 'new': new_value}
+
+ # Set the values for the email
+ msg = MIMEText(message_text)
+ msg['Subject'] = _('Job percentage changed')
+ msg['From'] = from_adress
+ msg['To'] = to_adress
+
+ # Send the email
+ try:
+ p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
+ p.communicate(msg.as_string())
+ except:
+ log.error("Error while sending Email")
# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
More information about the Mpuls-commits
mailing list