Skip to content
This repository
Browse code

Merge pull request #72 from noelph/master

Theaded Sending of Email
  • Loading branch information...
commit 16529f8d0bb3ae6044d8722828b855b99ab5f6b7 2 parents 1fd1e55 + 6e18353
Dominik Szopa authored February 25, 2013

Showing 1 changed file with 28 additions and 9 deletions. Show diff stats Hide diff stats

  1. 37  src/moderation/moderator.py
37  src/moderation/moderator.py
... ...
@@ -1,3 +1,4 @@
  1
+from threading import Thread
1 2
 from django.contrib.auth.models import Group
2 3
 from django.contrib.sites.models import Site
3 4
 from django.core.exceptions import ObjectDoesNotExist
@@ -11,6 +12,18 @@
11 12
 from moderation.managers import ModerationObjectsManager
12 13
 
13 14
 
  15
+class EmailThread(Thread):
  16
+    def __init__(self, obj, obj_method, *args, **kwargs):
  17
+        super(EmailThread, self).__init__()
  18
+        self.obj = obj
  19
+        self.obj_method = obj_method
  20
+        self.args = args
  21
+        self.kwargs = kwargs
  22
+        
  23
+    def run(self):
  24
+        getattr(self.obj, self.obj_method)(*self.args, **self.kwargs)
  25
+
  26
+
14 27
 class GenericModerator(object):
15 28
     """
16 29
     Encapsulates moderation options for a given model.
@@ -131,10 +144,13 @@ def inform_moderator(self,
131 144
         from moderation.conf.settings import MODERATORS
132 145
 
133 146
         if self.notify_moderator:
134  
-            self.send(content_object=content_object,
135  
-                      subject_template=self.subject_template_moderator,
136  
-                      message_template=self.message_template_moderator,
137  
-                      recipient_list=MODERATORS)
  147
+            EmailThread(
  148
+                self, 'send',
  149
+                content_object=content_object,
  150
+                subject_template=self.subject_template_moderator,
  151
+                message_template=self.message_template_moderator,
  152
+                recipient_list=MODERATORS
  153
+            ).start()
138 154
 
139 155
     def inform_user(self, content_object,
140 156
                     user,
@@ -145,11 +161,14 @@ def inform_user(self, content_object,
145 161
         else:
146 162
             extra_context = {'user': user}
147 163
         if self.notify_user:
148  
-            self.send(content_object=content_object,
149  
-                      subject_template=self.subject_template_user,
150  
-                      message_template=self.message_template_user,
151  
-                      recipient_list=[user.email],
152  
-                      extra_context=extra_context)
  164
+            EmailThread(
  165
+                self, 'send',
  166
+                content_object=content_object,
  167
+                subject_template=self.subject_template_user,
  168
+                message_template=self.message_template_user,
  169
+                recipient_list=[user.email],
  170
+                extra_context=extra_context
  171
+            ).start()
153 172
 
154 173
     def _get_base_managers(self):
155 174
         base_managers = []

0 notes on commit 16529f8

Please sign in to comment.
Something went wrong with that request. Please try again.