From 483be51cc35cd77cf2176eb2cc494dbf95869af8 Mon Sep 17 00:00:00 2001
From: Parbhat Puri <parbhatpuri17@gmail.com>
Date: Tue, 3 Dec 2019 11:18:26 +0000
Subject: [PATCH] Set source from sources in case of batch operation as source
 is used in most methods

---
 opentech/apply/activity/messaging.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/opentech/apply/activity/messaging.py b/opentech/apply/activity/messaging.py
index 77a92b8a1..43b5b0c66 100644
--- a/opentech/apply/activity/messaging.py
+++ b/opentech/apply/activity/messaging.py
@@ -144,6 +144,12 @@ class AdapterBase:
         self.process_send(message_type, recipients, [event], request, user, source, related=related, **kwargs)
 
     def process_send(self, message_type, recipients, events, request, user, source, sources=list(), related=None, **kwargs):
+        try:
+            # If this was a batch action we want to pull out the submission
+            source = sources[0]
+        except IndexError:
+            pass
+
         kwargs = {
             'request': request,
             'user': user,
@@ -335,12 +341,6 @@ class ActivityAdapter(AdapterBase):
         from .models import Activity
         visibility = kwargs.get('visibility', ALL)
 
-        try:
-            # If this was a batch action we want to pull out the submission
-            source = sources[0]
-        except IndexError:
-            pass
-
         related = kwargs['related']
         if isinstance(related, dict):
             try:
@@ -773,11 +773,11 @@ class EmailAdapter(AdapterBase):
 
     def send_message(self, message, source, subject, recipient, logs, **kwargs):
         try:
-            from_email = source.page.specific.from_address
-        except AttributeError:  # we're dealing with a project
-            from_email = source.submission.page.specific.from_address
+            try:
+                from_email = source.page.specific.from_address
+            except AttributeError:  # we're dealing with a project
+                from_email = source.submission.page.specific.from_address
 
-        try:
             send_mail(
                 subject,
                 message,
-- 
GitLab