Permalink
Browse files

Merge pull request #72 from noelph/master

Theaded Sending of Email
  • Loading branch information...
2 parents 1fd1e55 + 6e18353 commit 16529f8d0bb3ae6044d8722828b855b99ab5f6b7 @dominno committed Feb 25, 2013
Showing with 28 additions and 9 deletions.
  1. +28 −9 src/moderation/moderator.py
@@ -1,3 +1,4 @@
+from threading import Thread
from django.contrib.auth.models import Group
from django.contrib.sites.models import Site
from django.core.exceptions import ObjectDoesNotExist
@@ -11,6 +12,18 @@
from moderation.managers import ModerationObjectsManager
+class EmailThread(Thread):
+ def __init__(self, obj, obj_method, *args, **kwargs):
+ super(EmailThread, self).__init__()
+ self.obj = obj
+ self.obj_method = obj_method
+ self.args = args
+ self.kwargs = kwargs
+
+ def run(self):
+ getattr(self.obj, self.obj_method)(*self.args, **self.kwargs)
+
+
class GenericModerator(object):
"""
Encapsulates moderation options for a given model.
@@ -131,10 +144,13 @@ def inform_moderator(self,
from moderation.conf.settings import MODERATORS
if self.notify_moderator:
- self.send(content_object=content_object,
- subject_template=self.subject_template_moderator,
- message_template=self.message_template_moderator,
- recipient_list=MODERATORS)
+ EmailThread(
+ self, 'send',
+ content_object=content_object,
+ subject_template=self.subject_template_moderator,
+ message_template=self.message_template_moderator,
+ recipient_list=MODERATORS
+ ).start()
def inform_user(self, content_object,
user,
@@ -145,11 +161,14 @@ def inform_user(self, content_object,
else:
extra_context = {'user': user}
if self.notify_user:
- self.send(content_object=content_object,
- subject_template=self.subject_template_user,
- message_template=self.message_template_user,
- recipient_list=[user.email],
- extra_context=extra_context)
+ EmailThread(
+ self, 'send',
+ content_object=content_object,
+ subject_template=self.subject_template_user,
+ message_template=self.message_template_user,
+ recipient_list=[user.email],
+ extra_context=extra_context
+ ).start()
def _get_base_managers(self):
base_managers = []

0 comments on commit 16529f8

Please sign in to comment.