Commits

Luke Plant committed a64a47e Merge

Merged from default

Comments (0)

Files changed (5)

cciw/officers/email.py

 from cciw.officers.references import reference_form_to_text
 from django.conf import settings
 from django.contrib import messages
-from django.core.mail import send_mail
+from django.core.mail import send_mail, EmailMessage
 from django.core.urlresolvers import reverse
 from django.utils.crypto import salted_hmac
 import cciw.middleware.threadlocals as threadlocals
                                                    hash=make_ref_form_url_hash(ref_id, prev_ref_id))))
 
 
-def send_reference_request_email(message, ref):
+def send_reference_request_email(message, ref, sending_officer):
     officer = ref.application.officer
-    send_mail_with_attachments("Reference for %s %s" % (officer.first_name, officer.last_name),
-                               message,
-                               settings.DEFAULT_FROM_EMAIL,
-                               [ref.referee.email],
-                               fail_silently=False)
-
+    EmailMessage(subject="Reference for %s %s" % (officer.first_name, officer.last_name),
+                 body=message,
+                 from_email=settings.DEFAULT_FROM_EMAIL,
+                 to=[ref.referee.email],
+                 headers={'Reply-To': sending_officer.email}).send()
 
 def send_leaders_reference_email(refform):
     """
                   leader_emails, fail_silently=False)
 
 
-def send_nag_by_officer(message, officer, ref):
-    send_mail("Need reference from %s" % ref.referee.name,
-              message,
-              settings.DEFAULT_FROM_EMAIL,
-              [officer.email],
-              fail_silently=False)
+def send_nag_by_officer(message, officer, ref, sending_officer):
+    EmailMessage(subject="Need reference from %s" % ref.referee.name,
+                 body=message,
+                 from_email=settings.DEFAULT_FROM_EMAIL,
+                 to=[officer.email],
+                 headers={'Reply-To': sending_officer.email}).send()
 
 
 def send_crb_consent_problem_email(message, officer, camps):

cciw/officers/tests/references.py

 
 LEADER_USERNAME = 'davestott'
 LEADER_PASSWORD = 'test_normaluser_password'
+LEADER_EMAIL = 'leader@somewhere.com'
 LEADER = (LEADER_USERNAME, LEADER_PASSWORD)
 
 # Data: Applications 1 to 3 are in year 2000, for camps in summer 2000
         tc.find("The following e-mail")
         tc.formvalue("2", "send", "send")
         tc.submit()
-        self.assertEqual(len([e for e in mail.outbox if "Reference for" in e.subject]), 1)
+        msgs = [e for e in mail.outbox if "Reference for" in e.subject]
+        self.assertEqual(len(msgs), 1)
+        self.assertEqual(msgs[0].extra_headers.get('Reply-To', ''), LEADER_EMAIL)
 
     def test_no_email(self):
         """
         tc.find("If you have confirmed")
         tc.find("""email address is now "Mr Referee1 Name <a_new_email_for_ref1@example.com>",""")
 
+    def test_nag(self):
+        """
+        Tests for 'nag officer' page
+        """
+        app = Application.objects.get(pk=1)
+        refinfo = app.references[0]
+        self._twill_login(LEADER)
+        tc.go(make_django_url("cciw.officers.views.nag_by_officer", year=2000, number=1) + "?ref_id=%d" % refinfo.id)
+        tc.code(200)
+        tc.find("to nag their referee")
+        tc.formvalue("1", "send", "send")
+        tc.submit()
+        msgs = [e for e in mail.outbox if "Need reference from" in e.subject]
+        self.assertEqual(len(msgs), 1)
+        self.assertEqual(msgs[0].extra_headers.get('Reply-To', ''), LEADER_EMAIL)
 
 class CreateReference(TwillMixin, TestCase):
     """

cciw/officers/views.py

                             applicant=app.officer,
                             camp=camp,
                             url=url,
+                            sender=request.user,
                             update=update)
     emailform = None
     messageform = None
         if 'send' in request.POST:
             messageform = SendReferenceRequestForm(request.POST, message_info=messageform_info)
             if messageform.is_valid():
-                send_reference_request_email(wordwrap(messageform.cleaned_data['message'], 70), ref)
+                send_reference_request_email(wordwrap(messageform.cleaned_data['message'], 70), ref, request.user)
                 ref.requested = True
                 ref.log_request_made(request.user, datetime.datetime.now())
                 ref.save()
     c = {}
     messageform_info = dict(referee=ref.referee,
                             officer=officer,
+                            sender=request.user,
                             camp=camp)
 
     if request.method == 'POST':
             messageform = SendNagByOfficerForm(request.POST, message_info=messageform_info)
             # It's impossible for the form to be invalid, so assume valid
             messageform.is_valid()
-            send_nag_by_officer(wordwrap(messageform.cleaned_data['message'], 70), officer, ref)
+            send_nag_by_officer(wordwrap(messageform.cleaned_data['message'], 70),
+                                officer, ref, request.user)
             return close_window_response()
         else:
             # cancel

templates/cciw/officers/nag_by_officer_email.txt

 
 Thanks.
 
-On behalf of the leaders of camp {{ camp.number }}, {{ camp.year }} - {{ camp.leaders_formatted }}.
+{{ sender.first_name }} {{ sender.last_name }}
+
+For CCIW camp {{ camp.number }}, {{ camp.year }} - {{ camp.leaders_formatted }}.
 {% endautoescape %}

templates/cciw/officers/request_reference_new.txt

 
 Many thanks for your support of CCIW.
 
-On behalf of the leaders of camp {{ camp.number }}, {{ camp.year }} - {{ camp.leaders_formatted }}.{% endautoescape %}
+{{ sender.first_name }} {{ sender.last_name }}
+
+For CCIW camp {{ camp.number }}, {{ camp.year }} - {{ camp.leaders_formatted }}.{% endautoescape %}