def object_comment(sender, instance, created, **kwargs): if isinstance(instance.content_object, Image): observed = instance.content_object signal = notice_type_label = "photos_image_comment" observer = user = instance.user if notification and created: if not notification.is_observing(observed, observer, signal): notification.observe(observed, observer, notice_type_label, signal) notice_uid = '{0}_{1}_{2}'.format( notice_type_label, Site.objects.get_current().pk, instance.pk ) notification.send_observation_notices_for( observed, signal, extra_context={ "context_object": instance, "notice_uid": notice_uid, "user": user, "image": observed, "comment": instance, "group": observed.group, } )
def object_comment(sender, instance, created, **kwargs): if isinstance(instance.content_object, Topic): observed = instance.content_object signal = notice_type_label = 'topic_comment' observer = user = instance.user Topic.objects.filter(pk=observed.pk).update(modified=datetime.now()) # Don't send a signal if notification and created: if not notification.is_observing(observed, observer, signal): notification.observe(observed, observer, notice_type_label, signal) notice_uid = '{0}_{1}_{2}'.format( notice_type_label, Site.objects.get_current().pk, instance.pk ) notification.send_observation_notices_for( observed, signal, extra_context={ "context_object": instance, "user": user, "topic": observed, "comment": instance, "group": observed.group, "notice_uid": notice_uid, } )
def object_comment(sender, instance, created, **kwargs): if isinstance(instance.content_object, Post): observed = instance.content_object signal = notice_type_label = "blog_post_comment" observer = user = instance.user # Post.objects.filter(pk=observed.pk).update(updated_at=datetime.now()) # Don't send a signal if notification and created: if not notification.is_observing(observed, observer, signal): notification.observe(observed, observer, notice_type_label, signal) notice_uid = '{0}_{1}_{2}'.format( notice_type_label, Site.objects.get_current().pk, instance.pk ) notification.send_observation_notices_for( observed, signal, extra_context={ "context_object": instance, "notice_uid": notice_uid, "user": user, "post": observed, "comment": instance } )
def feedback_signal_handler(sender, **kwargs): """ All watchers of a decision will get a notification informing them of new feedback. All watchers become observers of the feedback. """ instance = kwargs.get('instance') headers = {'Message-ID': instance.get_message_id()} headers.update({'In-Reply-To': instance.decision.get_message_id()}) if kwargs.get('created', True): #author gets notified if the feedback is edited. notification.observe(instance, instance.author, 'feedback_change') #All watchers of parent get notified of new feedback. all_observed_items_but_authors = list( instance.decision.watchers.exclude(user=instance.author)) observer_list = [x.user for x in all_observed_items_but_authors] extra_context = dict({"observed": instance}) notification.send(observer_list, "feedback_new", extra_context, headers, from_email=instance.decision.get_email()) else: notification.send_observation_notices_for(instance, headers=headers)
def comment_signal_handler(sender, **kwargs): """ All watchers of a decision will get a notification informing them of new comment. All watchers become observers of the comment. """ instance = kwargs.get('instance') headers = { 'Message-ID': "comment-%s@%s" % (instance.id, Site.objects.get_current().domain) } headers.update( {'In-Reply-To': instance.content_object.get_message_id()}) if kwargs.get('created', True): # Creator gets notified if the comment is edited. notification.observe(instance, instance.user, 'comment_change') #All watchers of parent get notified of new comment. all_observed_items_but_author = list( instance.content_object.decision.watchers.exclude( user=instance.user)) observer_list = [x.user for x in all_observed_items_but_author] extra_context = dict({"observed": instance}) notification.send( observer_list, "comment_new", extra_context, headers, from_email=instance.content_object.decision.get_email()) else: notification.send_observation_notices_for(instance, headers=headers)
def decision_signal_handler(sender, **kwargs): """ All users except the author will get a notification informing them of new content. All users are made observers of the decision. Notices are sent for observed decisions when feedback changes. """ instance = kwargs.get('instance') headers = {'Message-ID': instance.get_message_id()} if kwargs.get('created', True): all_users = instance.organization.users.all() all_but_author = all_users.exclude(username=instance.author) for user in all_users: notification.observe(instance, user, 'decision_change') extra_context = {} extra_context.update({"observed": instance}) notification.send(all_but_author, "decision_new", extra_context, headers, from_email=instance.get_email()) else: notification.send_observation_notices_for(instance, headers=headers)
def pin_favorite_handler(user, target, instance, **kwargs): ''' user: the user who acted target: the pin that has been followed instance: the follow object ''' from notification import models as notification #notify pin's followers notification.send_observation_notices_for(target, "favorited", { "from_user": user, "owner": target.submitter }, [user]) #notify user's followers notification.send_observation_notices_for(user, "favorited", { "from_user": user, "owner": target.submitter }, [user], sender=target) if user != target.submitter: #notify pin's owner notification.send([target.submitter], "favorited", {"from_user": user}, sender=target) #make user observe new comments notification.observe(target, user, "commented") #make user observe new favorites notification.observe(target, user, "favorited")
def pin_comment_handler(sender, *args, **kwargs): comment = kwargs.pop('instance', None) print comment user = comment.user target = comment.content_object from notification import models as notification #notify pin followers notification.send_observation_notices_for(target, "commented", { "from_user": user, "owner": target.submitter }, [user]) #notify user's followers notification.send_observation_notices_for(user, "commented", { "from_user": user, "alter_desc": True, "owner": target.submitter }, [user], sender=target) if user != target.submitter: #notify pin's owner notification.send([target.submitter], "commented", {"from_user": user}, sender=target) #make comment user observe new comments notification.observe(target, user, "commented")
def new_pin_handler(sender, *args, **kwargs): pin = kwargs.pop('instance', None) user = pin.submitter target = pin from notification import models as notification #notify user's followers notification.send_observation_notices_for(user, "new", {"from_user": user, "owner": target.submitter}, [user], sender=target)
def new_pin_handler(sender, *args, **kwargs): pin = kwargs.pop('instance', None) user = pin.submitter target = pin from notification import models as notification #notify user's followers notification.send_observation_notices_for(user, "new", { "from_user": user, "owner": target.submitter }, [user], sender=target)
def user_follow_handler(user, target, instance, **kwargs): ''' user: the user who acted target: the user that has been followed instance: the follow object ''' from notification import models as notification notification.send_observation_notices_for(target, "followed", {"from_user": user, "owner": target}, [user]) if user != target: notification.send([target], "followed", {"from_user": user}, sender=user) notification.observe(target, user, "followed") notification.observe(target, user, "new") notification.observe(target, user, "favorited") notification.observe(target, user, "commented")
def pin_comment_handler(sender, *args, **kwargs): comment = kwargs.pop('instance', None) print comment user = comment.user target = comment.content_object from notification import models as notification #notify pin followers notification.send_observation_notices_for(target, "commented", {"from_user": user, "owner":target.submitter}, [user]) #notify user's followers notification.send_observation_notices_for(user, "commented", {"from_user": user, "alter_desc":True, "owner":target.submitter}, [user], sender=target) if user != target.submitter: #notify pin's owner notification.send([target.submitter], "commented", {"from_user": user}, sender=target) #make comment user observe new comments notification.observe(target, user, "commented")
def pin_favorite_handler(user, target, instance, **kwargs): ''' user: the user who acted target: the pin that has been followed instance: the follow object ''' from notification import models as notification #notify pin's followers notification.send_observation_notices_for(target, "favorited", {"from_user": user, "owner": target.submitter}, [user]) #notify user's followers notification.send_observation_notices_for(user, "favorited", {"from_user": user, "owner": target.submitter}, [user], sender=target) if user != target.submitter: #notify pin's owner notification.send([target.submitter], "favorited", {"from_user": user}, sender=target) #make user observe new comments notification.observe(target, user, "commented") #make user observe new favorites notification.observe(target, user, "favorited")
def user_follow_handler(user, target, instance, **kwargs): ''' user: the user who acted target: the user that has been followed instance: the follow object ''' from notification import models as notification notification.send_observation_notices_for(target, "followed", { "from_user": user, "owner": target }, [user]) if user != target: notification.send([target], "followed", {"from_user": user}, sender=user) notification.observe(target, user, "followed") notification.observe(target, user, "new") notification.observe(target, user, "favorited") notification.observe(target, user, "commented")
def decision_signal_handler(sender, **kwargs): """ All users except the author will get a notification informing them of new content. All users are made observers of the decision. Notices are sent for observed decisions when feedback changes. """ instance = kwargs.get('instance') headers = {'Message-ID' : instance.get_message_id()} if kwargs.get('created', True): all_users = instance.organization.users.all() all_but_author = all_users.exclude(username=instance.author) for user in all_users: notification.observe(instance, user, 'decision_change') extra_context = {} extra_context.update({"observed": instance}) notification.send(all_but_author, "decision_new", extra_context, headers, from_email=instance.get_email()) else: notification.send_observation_notices_for(instance, headers=headers)
def feedback_signal_handler(sender, **kwargs): """ All watchers of a decision will get a notification informing them of new feedback. All watchers become observers of the feedback. """ instance = kwargs.get('instance') headers = {'Message-ID' : instance.get_message_id()} headers.update({'In-Reply-To' : instance.decision.get_message_id()}) if kwargs.get('created', True): #author gets notified if the feedback is edited. notification.observe(instance, instance.author, 'feedback_change') #All watchers of parent get notified of new feedback. all_observed_items_but_authors = list(instance.decision.watchers.exclude(user=instance.author)) observer_list = [x.user for x in all_observed_items_but_authors] extra_context = dict({"observed": instance}) notification.send(observer_list, "feedback_new", extra_context, headers, from_email=instance.decision.get_email()) else: notification.send_observation_notices_for(instance, headers=headers)
def comment_signal_handler(sender, **kwargs): """ All watchers of a decision will get a notification informing them of new comment. All watchers become observers of the comment. """ instance = kwargs.get('instance') headers = {'Message-ID' : "comment-%s@%s" % (instance.id, Site.objects.get_current().domain)} headers.update({'In-Reply-To' : instance.content_object.get_message_id()}) if kwargs.get('created', True): # Creator gets notified if the comment is edited. notification.observe(instance, instance.user, 'comment_change') #All watchers of parent get notified of new comment. all_observed_items_but_author = list(instance.content_object.decision.watchers.exclude(user=instance.user)) observer_list = [x.user for x in all_observed_items_but_author] extra_context = dict({"observed": instance}) notification.send(observer_list, "comment_new", extra_context, headers, from_email=instance.content_object.decision.get_email()) else: notification.send_observation_notices_for(instance, headers=headers)
def on_feedback_updated(sender, *args, **kwargs): notification.send_observation_notices_for(sender, 'feedback_updated', {'feedback': sender})