--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/iconolab/mails.py Wed Apr 12 14:36:44 2017 +0200
@@ -0,0 +1,41 @@
+from django.conf import settings
+from django.core.mail import send_mail
+from django.core.urlresolvers import reverse
+
+class EmailManager():
+
+ VERB_NEW_COMMENT = 'a écrit un commentaire sur votre annotation'
+ VERB_NEW_REPLY = 'a répondu à votre commentaire'
+ VERB_NEW_ANNOTATION = 'a proposé une révision sur votre annotation'
+ VERB_ACCEPTED_REVISION = 'a étudié votre révision'
+ VERB_REQUEST_FOR_CONTRIBUTION = 'a fait un appel à contribution'
+ VERB_REQUEST_FOR_EXPERTISE = 'a fait un appel à expertise'
+
+ def __message_content(self):
+ return 'Connectez-vous pour voir les notifications \n\n' + settings.BASE_URL + reverse('user_notifications')
+
+ def __send_mail(self, recipient, verb):
+ send_mail(
+ 'Un utilisateur ' + verb,
+ self.__message_content(),
+ settings.CONTACT_EMAIL,
+ [recipient.email]
+ )
+
+ def new_comment(self, recipient):
+ self.__send_mail(recipient, self.VERB_NEW_COMMENT)
+
+ def new_reply(self, recipient):
+ self.__send_mail(recipient, self.VERB_NEW_REPLY)
+
+ def new_revision(self, recipient):
+ self.__send_mail(recipient, self.VERB_NEW_ANNOTATION)
+
+ def accepted_revision(self, recipient):
+ self.__send_mail(recipient, self.VERB_ACCEPTED_REVISION)
+
+ def request_for_contribution(self, recipient):
+ self.__send_mail(recipient, self.VERB_REQUEST_FOR_CONTRIBUTION)
+
+ def request_for_expertise(self, recipient):
+ self.__send_mail(recipient, self.VERB_REQUEST_FOR_EXPERTISE)
--- a/src/iconolab/signals/handlers.py Tue Mar 21 13:42:17 2017 +0100
+++ b/src/iconolab/signals/handlers.py Wed Apr 12 14:36:44 2017 +0200
@@ -1,10 +1,9 @@
from django.apps import apps
from django.conf import settings
-from django.core.mail import send_mail
-from django.core.urlresolvers import reverse
from django.db.models.signals import post_save
from django.dispatch import Signal, receiver
from notifications.signals import notify
+from iconolab.mails import EmailManager
import logging
logger = logging.getLogger(__name__)
@@ -14,44 +13,6 @@
revision_rejected = Signal(providing_args=['instance'])
revision_created = Signal(providing_args=['instance'])
-VERB_NEW_COMMENT = 'a écrit un commentaire sur votre annotation'
-VERB_NEW_REPLY = 'a répondu à votre commentaire'
-VERB_NEW_ANNOTATION = 'a proposé une révision sur votre annotation'
-VERB_ACCEPTED_REVISION = 'a étudié votre révision'
-VERB_REQUEST_FOR_CONTRIBUTION = 'a fait un appel à contribution'
-VERB_REQUEST_FOR_EXPERTISE = 'a fait un appel à expertise'
-
-class EmailManager():
-
- def __message_content(self):
- return 'Connectez-vous pour voir les notifications \n\n' + settings.BASE_URL + reverse('user_notifications')
-
- def __send_mail(self, recipient, verb):
- send_mail(
- 'Un utilisateur ' + verb,
- self.__message_content(),
- settings.CONTACT_EMAIL,
- [recipient.email]
- )
-
- def new_comment(self, recipient):
- self.__send_mail(recipient, VERB_NEW_COMMENT)
-
- def new_reply(self, recipient):
- self.__send_mail(recipient, VERB_NEW_REPLY)
-
- def new_revision(self, recipient):
- self.__send_mail(recipient, VERB_NEW_ANNOTATION)
-
- def accepted_revision(self, recipient):
- self.__send_mail(recipient, VERB_ACCEPTED_REVISION)
-
- def request_for_contribution(self, recipient):
- self.__send_mail(recipient, VERB_REQUEST_FOR_CONTRIBUTION)
-
- def request_for_expertise(self, recipient):
- self.__send_mail(recipient, VERB_REQUEST_FOR_EXPERTISE)
-
emailManager = EmailManager()
def increment_stats_on_new_revision(sender, instance, **kwargs):
@@ -187,12 +148,12 @@
parent_comment = IconolabComment.objects.get(id=instance.parent_id)
if parent_comment.user != instance.user:
emailManager.new_reply(parent_comment.user)
- notify.send(instance.user, recipient=parent_comment.user, verb=VERB_NEW_REPLY, action_object=instance, target=comment_annotation, emailed=True)
+ notify.send(instance.user, recipient=parent_comment.user, verb=EmailManager.VERB_NEW_REPLY, action_object=instance, target=comment_annotation, emailed=True)
if parent_comment.user == comment_annotation.author:
notified_author = True
if instance.user != comment_annotation.author and not notified_author:
emailManager.new_comment(comment_annotation.author)
- notify.send(instance.user, recipient=comment_annotation.author, verb=VERB_NEW_COMMENT, action_object=instance, target=comment_annotation, emailed=True)
+ notify.send(instance.user, recipient=comment_annotation.author, verb=EmailManager.VERB_NEW_COMMENT, action_object=instance, target=comment_annotation, emailed=True)
def notify_users_on_metacategory(sender, instance, created, **kwargs):
"""
@@ -207,29 +168,29 @@
if related_metacategory.triggers_notifications == MetaCategory.COMMENTERS:
for commenter in comment_annotation.stats.commenters.exclude(id=related_comment.user.id).all():
emailManager.request_for_contribution(commenter)
- notify.send(related_comment.user, recipient=commenter, verb=VERB_REQUEST_FOR_CONTRIBUTION, action_object=related_comment, target=comment_annotation, emailed=True)
+ notify.send(related_comment.user, recipient=commenter, verb=EmailManager.VERB_REQUEST_FOR_CONTRIBUTION, action_object=related_comment, target=comment_annotation, emailed=True)
elif related_metacategory.triggers_notifications == MetaCategory.CONTRIBUTORS:
for contributor in comment_annotation.stats.contributors.exclude(id=related_comment.user.id).all():
emailManager.request_for_contribution(contributor)
- notify.send(related_comment.user, recipient=contributor, verb=VERB_REQUEST_FOR_CONTRIBUTION, action_object=related_comment, target=comment_annotation, emailed=True)
+ notify.send(related_comment.user, recipient=contributor, verb=EmailManager.VERB_REQUEST_FOR_CONTRIBUTION, action_object=related_comment, target=comment_annotation, emailed=True)
if related_metacategory.triggers_notifications == MetaCategory.COLLECTION_ADMINS:
for collection_admin in comment_annotation.image.item.collection.admins.all():
emailManager.request_for_expertise(collection_admin.user)
- notify.send(related_comment.user, recipient=collection_admin.user, verb=VERB_REQUEST_FOR_EXPERTISE, action_object=related_comment, target=comment_annotation, emailed=True)
+ notify.send(related_comment.user, recipient=collection_admin.user, verb=EmailManager.VERB_REQUEST_FOR_EXPERTISE, action_object=related_comment, target=comment_annotation, emailed=True)
def notify_users_on_new_revision(sender, instance, **kwargs):
from iconolab.models import AnnotationRevision
if sender == AnnotationRevision:
if instance.author != instance.annotation.author:
emailManager.new_revision(instance.annotation.author)
- notify.send(instance.author, recipient=instance.annotation.author, verb=VERB_NEW_ANNOTATION, action_object=instance, target=instance.annotation, emailed=True)
+ notify.send(instance.author, recipient=instance.annotation.author, verb=EmailManager.VERB_NEW_ANNOTATION, action_object=instance, target=instance.annotation, emailed=True)
def notify_users_on_accepted_revision(sender, instance, **kwargs):
from iconolab.models import AnnotationRevision
if sender == AnnotationRevision:
if instance.author != instance.annotation.author and instance.state in [AnnotationRevision.ACCEPTED, AnnotationRevision.STUDIED]:
emailManager.accepted_revision(instance.author)
- notify.send(instance.annotation.author, recipient=instance.author, verb=VERB_ACCEPTED_REVISION, action_object=instance, target=instance.annotation, emailed=True)
+ notify.send(instance.annotation.author, recipient=instance.author, verb=EmailManager.VERB_ACCEPTED_REVISION, action_object=instance, target=instance.annotation, emailed=True)
def create_user_profile(sender, instance, created, **kwargs):
from iconolab.models import UserProfile