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 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 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(), 'In-Reply-To': instance.decision.get_message_id(), 'References': instance.decision.get_message_id() } headers.update(STANDARD_SENDING_HEADERS) instance.decision.note_external_modification() 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: # An edit by someone other than the author never counts as minor if instance.author != instance.editor or not instance.minor_edit: send_observation_notices_for(instance, headers=headers, from_email=instance.decision.get_email())
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 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), 'In-Reply-To': instance.content_object.get_message_id(), 'References': ' '.join(( instance.content_object.decision.get_message_id(), instance.content_object.get_message_id())) } headers.update(STANDARD_SENDING_HEADERS) instance.content_object.decision.note_external_modification() 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: send_observation_notices_for(instance, headers=headers, from_email=instance.content_object.decision.get_email())
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 form_valid(self, form, *args, **kwargs): form.instance.editor = self.request.user if not notification.is_observing(self.object.decision, self.request.user): notification.observe(self.object.decision, self.request.user, 'decision_change') return super(FeedbackUpdate, self).form_valid(form, *args, **kwargs)
def post_release_save_handler(sender, instance, created, user, **kwargs): if settings.ENABLE_NOTICES: release = instance project = release.project users = [ watch.user for watch in notification.ObservedItem.objects.filter( content_type__model='project', object_id=project.id, signal="project_changed").select_related('user') ] for user in users: try: notification.ObservedItem.objects.get_for( release.project, user, "project_changed") if created: for signal in release_signals: try: notification.ObservedItem.objects.get_for( release, user, signal) except notification.ObservedItem.DoesNotExist: notification.observe(release, user, signal, signal) nt = "project_release_added" else: nt = "project_release_changed" project = release.project _notify_releasewatchers(project, release, nt) except notification.ObservedItem.DoesNotExist, e: logger.debug("Watches: %s" % unicode(e))
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 change_observers(watch, decision, watcher): if watch: if not notification.is_observing(decision, watcher): notification.observe(decision, watcher, DECISION_CHANGE) else: if notification.is_observing(decision, watcher): notification.stop_observing(decision, watcher)
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 post_resource_save_handler(sender, instance, created, user, **kwargs): if settings.ENABLE_NOTICES: resource = instance project = resource.project users = [ watch.user for watch in notification.ObservedItem.objects.filter( content_type__model="project", object_id=project.id, signal="project_changed" ).select_related("user") ] for user in users: try: notification.ObservedItem.objects.get_for(resource.project, user, "project_changed") if created: for signal in resource_signals: try: notification.ObservedItem.objects.get_for(resource, user, signal) except notification.ObservedItem.DoesNotExist: notification.observe(resource, user, signal, signal) nt = "project_resource_added" else: nt = "project_resource_changed" project = resource.project _notify_resourcewatchers(project, resource, nt) except notification.ObservedItem.DoesNotExist, e: logger.debug("Watches: %s" % unicode(e))
def observe_toggle(request, content_type_id, object_id, signal, notice_type_label): success = False observing = None try: content_type = ContentType.objects.get(pk=content_type_id) observed = content_type.get_object_for_this_type(pk=object_id) if not is_observing(observed=observed, observer=request.user, signal=signal): observe(observed=observed, observer=request.user, notice_type_label=notice_type_label, signal=signal) observing = True else: stop_observing(observed=observed, observer=request.user, signal=signal) observing = False success = True except: pass return HttpResponse( json.dumps({"success": success, "observing": observing, }), mimetype='application/json; charset=utf-8', status=200 )
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 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 subscribe_creator(sender, instance, created, **kwargs): if notification and created and isinstance(instance, Article): for observer, notice_type_label, signal in ( (instance.creator, 'wiki_article_edited', 'post_save'), (instance.creator, 'wiki_article_comment', 'wiki_article_comment'), ): if observer and not notification.is_observing(instance, observer, signal): notification.observe(instance, observer, notice_type_label, signal)
def test_change_observers_removes_when_watching_and_watch_false( self, stop_observe ): feedback = self.create_and_return_feedback() observe(feedback.decision, feedback.author, DECISION_CHANGE) form = NotificationsForm(instance=feedback) form.cleaned_data = {'watch': False} form.change_observers(feedback.decision, feedback.author) self.assertTrue(stop_observe.called)
def form_valid(self, form): form.instance.editor = self.request.user form.instance.last_status = self.last_status if not form.cleaned_data['watch'] and notification.is_observing(self.object, self.request.user): notification.stop_observing(self.object, self.request.user) elif form.cleaned_data['watch'] and not notification.is_observing(self.object, self.request.user): notification.observe(self.object, self.request.user, 'decision_change') return super(DecisionUpdate, self).form_valid(form)
def test_change_observers_doesnt_add_when_watching_and_watch_true( self, observe_method ): feedback = self.create_and_return_feedback() observe(feedback.decision, feedback.author, DECISION_CHANGE) form = NotificationsForm(instance=feedback) form.cleaned_data = {'watch': True} form.change_observers(feedback.decision, feedback.author) self.assertFalse(observe_method.called)
def test_changing_organization_deletes_watchers(self): decision = self.create_and_return_decision() observe(decision, self.user, DECISION_CHANGE) decision.organization = G(Organization) decision.save() decision = Decision.objects.get(pk=decision.id) self.assertSequenceEqual([], decision.watchers.all())
def observe_article(request, title, group_slug=None, bridge=None, article_qs=ALL_ARTICLES, template_name='recentchanges.html', template_dir='wiki', extra_context=None, is_member=None, is_private=None, *args, **kw): if request.method == 'POST': article_args = {'title': title} group = None if group_slug is not None: try: group = bridge.get_group(group_slug) except ObjectDoesNotExist: raise Http404 article_args.update({ 'content_type': get_ct(group), 'object_id': group.id }) allow_read = has_read_perm(request.user, group, is_member, is_private) else: group = None allow_read = True if not allow_read: return HttpResponseForbidden() article = get_object_or_404(article_qs, **article_args) notification.observe(article, request.user, 'wiki_observed_article_changed') url = get_url('wiki_article', group, kw={ 'title': article.title, }, bridge=bridge) return redirect_to(request, url) return HttpResponseNotAllowed(['POST'])
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_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. """ if kwargs.get('created', True): instance = kwargs.get('instance') 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, from_email=instance.get_email())
def new_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. """ if kwargs.get('created', True): instance = kwargs.get('instance') #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, from_email=instance.decision.get_email())
def form_valid(self, form): form.instance.editor = self.request.user form.instance.last_status = self.last_status form.instance.minor_edit = form.cleaned_data['minor_edit'] if (not form.cleaned_data['watch'] and notification.is_observing(self.object, self.request.user)): notification.stop_observing(self.object, self.request.user) elif (form.cleaned_data['watch'] and not notification.is_observing(self.object, self.request.user)): notification.observe( self.object, self.request.user, DECISION_CHANGE ) return super(DecisionUpdate, self).form_valid(form)
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. """ instance = kwargs.get('instance') headers = {'Message-ID' : instance.get_message_id()} headers.update(STANDARD_SENDING_HEADERS) if kwargs.get('created', True): active_users = instance.organization.users.filter(is_active=True) all_but_author = active_users.exclude(username=instance.author) for user in active_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())
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 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 observe_article(request, title, group_slug=None, bridge=None, article_qs=ALL_ARTICLES, template_name='recentchanges.html', template_dir='wiki', extra_context=None, is_member=None, is_private=None, *args, **kw): if request.method == 'POST': article_args = {'title': title} group = None if group_slug is not None: try: group = bridge.get_group(group_slug) except ObjectDoesNotExist: raise Http404 article_args.update({'content_type': get_ct(group), 'object_id': group.id}) allow_read = has_read_perm(request.user, group, is_member, is_private) else: group = None allow_read = True if not allow_read: return HttpResponseForbidden() article = get_object_or_404(article_qs, **article_args) notification.observe(article, request.user, 'wiki_observed_article_changed') url = get_url('wiki_article', group, kw={ 'title': article.title, }, bridge=bridge) return redirect_to(request, url) return HttpResponseNotAllowed(['POST'])
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. """ instance = kwargs.get('instance') headers = {'Message-ID': instance.get_message_id()} headers.update(STANDARD_SENDING_HEADERS) if kwargs.get('created', True): active_users = instance.organization.users.filter(is_active=True) all_but_author = active_users.exclude(username=instance.author) for user in active_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())
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 observe_topic(request, topic_id, group_slug=None, bridge=None, topic_qs=ALL_TOPICS, template_name='recentchanges.html', template_dir='forums', extra_context=None, is_member=None, is_private=None, *args, **kw): if request.method == 'POST': topic_args = {'id': topic_id} group = None if group_slug is not None: try: group = bridge.get_group(group_slug) except ObjectDoesNotExist: raise Http404 topic_args.update({'content_type': get_ct(group), 'object_id': group.id}) allow_read = has_read_perm(request.user, group, is_member, is_private) else: group = None allow_read = True if not allow_read: return HttpResponseForbidden() topic = get_object_or_404(topic_qs, **topic_args) notification.observe(topic, request.user, 'forums_observed_topic_changed') url = get_url('forums_topic', group, kw={ 'topic_id': topic.id, }, bridge=bridge) return redirect_to(request, url) return HttpResponseNotAllowed(['POST'])
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 project_toggle_watch(request, project_slug): """Add/Remove watches on a project for a specific user.""" if request.method != 'POST': return json_error(_('Must use POST to activate')) if not settings.ENABLE_NOTICES: return json_error(_('Notification is not enabled')) project = get_object_or_404(Project, slug=project_slug) url = reverse('project_toggle_watch', args=(project_slug,)) project_signals = ['project_changed', 'project_deleted',] try: result = { 'style': 'watch_add', 'title': _('Watch this project'), 'project': True, 'url': url, 'error': None, } for signal in project_signals: notification.stop_observing(project, request.user, signal) except notification.ObservedItem.DoesNotExist: try: result = { 'style': 'watch_remove', 'title': _('Stop watching this project'), 'project': True, 'url': url, 'error': None, } for signal in project_signals: notification.observe(project, request.user, signal, signal) except WatchException, e: return json_error(e.message, result)
def observe_article(request, title, group_slug=None, group_slug_field=None, group_qs=None, article_qs=ALL_ARTICLES, template_name='recentchanges.html', template_dir='wiki', extra_context=None, is_member=None, is_private=None, *args, **kw): if request.method == 'POST': article_args = {'title': title} group = None if group_slug is not None: group = get_object_or_404(group_qs,**{group_slug_field: group_slug}) article_args.update({'content_type': get_ct(group), 'object_id': group.id}) allow_read = has_read_perm(request.user, group, is_member, is_private) else: allow_read = True if not allow_read: return HttpResponseForbidden() article = get_object_or_404(article_qs, **article_args) notification.observe(article, request.user, 'wiki_observed_article_changed') url = get_url('wiki_article', group, [article.title], {'title': article.title, 'group_slug': group_slug}) return HttpResponseRedirect(url) return HttpResponseNotAllowed(['POST'])
def observe_article(request, title, group_slug=None, group_slug_field=None, group_qs=None, article_qs=ALL_ARTICLES, template_name='recentchanges.html', template_dir='wiki', extra_context=None, is_member=None, is_private=None, *args, **kw): article_args = {'title': title} group = None if group_slug is not None: group = get_object_or_404(group_qs, **{group_slug_field: group_slug}) article_args.update({ 'content_type': get_ct(group), 'object_id': group.id }) allow_read = has_read_perm(request.user, group, is_member, is_private) else: allow_read = True if not allow_read: return HttpResponseForbidden() article = get_object_or_404(article_qs, **article_args) if not notification.is_observing(article, request.user): notification.observe(article, request.user, 'wiki_observed_article_changed') return redirect(article) return HttpResponseNotAllowed(['POST'])
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(), 'In-Reply-To': instance.decision.get_message_id(), 'References': instance.decision.get_message_id() } headers.update(STANDARD_SENDING_HEADERS) instance.decision.note_external_modification() 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: # An edit by someone other than the author never counts as minor if instance.author != instance.editor or not instance.minor_edit: send_observation_notices_for( instance, headers=headers, from_email=instance.decision.get_email())
def save(self, *args, **kwargs): # 0 - Extra data comment = self.cleaned_data['comment'] # 2 - Save the Article article = super(ArticleForm, self).save(*args, **kwargs) # 3 - Set creator and group editor = getattr(self, 'editor', None) group = getattr(self, 'group', None) if self.is_new: if editor is not None: article.creator = editor article.group = group article.save(*args, **kwargs) if notification: notification.observe(article, editor, 'wiki_observed_article_changed') # 4 - Create new revision changeset = article.new_revision(self.old_content, self.old_title, self.old_markup, comment, editor) return article, changeset
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 _update_notification_for_org_change(self): self.watchers.all().delete() org_users = self.organization.users.all() for user in org_users: notification.observe(self, user, 'decision_change') for feedback in self.feedback_set.all(): feedback.watchers.all().delete() for user in org_users: notification.observe(feedback, user, 'feedback_change') for comment in feedback.comments.all(): comment_watchers = notification.ObservedItem.objects.filter( content_type=ContentType.objects.get(name='comment'), object_id=comment.id) comment_watchers.delete() for user in org_users: notification.observe(comment, user, 'comment_change')
def save(self, *args, **kwargs): self.excerpt = self._get_excerpt() if self.id: if self.__class__.objects.get(id=self.id).organization.id != self.organization.id: self.watchers.all().delete() org_users = self.organization.users.all() for user in org_users: notification.observe(self, user, 'decision_change') for feedback in self.feedback_set.all(): feedback.watchers.all().delete() for user in org_users: notification.observe(feedback, user, 'feedback_change') for comment in feedback.comments.all(): comment_watchers = notification.ObservedItem.objects.filter( content_type = ContentType.objects.get(name='comment'), object_id = comment.id) comment_watchers.delete() for user in org_users: notification.observe(comment, user, 'comment_change') super(Decision, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.excerpt = self._get_excerpt() if self.id: if self.__class__.objects.get( id=self.id).organization.id != self.organization.id: self.watchers.all().delete() org_users = self.organization.users.all() for user in org_users: notification.observe(self, user, 'decision_change') for feedback in self.feedback_set.all(): feedback.watchers.all().delete() for user in org_users: notification.observe(feedback, user, 'feedback_change') for comment in feedback.comments.all(): comment_watchers = notification.ObservedItem.objects.filter( content_type=ContentType.objects.get( name='comment'), object_id=comment.id) comment_watchers.delete() for user in org_users: notification.observe(comment, user, 'comment_change') super(Decision, self).save(*args, **kwargs)
def subscribe_user(user, feedback): """ Subscribe a user to any change of a given feedback """ if not notification.is_observing(feedback, user, signal='feedback_updated'): notification.observe(feedback, user, 'feedback_updated', 'feedback_updated')
def resource_translation_toggle_watch(request, project_slug, resource_slug, language_code): """Add/Remove a TranslationWatch for a specific user.""" if request.method != 'POST': return json_error(_('Must use POST to activate')) if not settings.ENABLE_NOTICES: return json_error(_('Notification is not enabled')) resource = get_object_or_404(Resource, slug=resource_slug, project__slug=project_slug) project = resource.project language = get_object_or_404(Language, code=language_code) team = Team.objects.get_or_none(project, language_code) check = ProjectPermission(request.user) if not check.submit_translations(team or project) and not \ check.maintain(project) and not \ request.user.has_perm('watches.add_translationwatch') and not \ request.user.has_perm('watches.delete_translationwatch'): return permission_denied(request) url = reverse('resource_translation_toggle_watch', args=(project_slug, resource_slug, language_code)) try: twatch = TranslationWatch.objects.get(resource=resource, language=language) result = { 'style': 'watch_add', 'title': _('Watch it'), 'id': twatch.id, 'url': url, 'error': None, } notification.stop_observing(twatch, request.user, signal='project_resource_translation_changed') except (TranslationWatch.DoesNotExist, notification.ObservedItem.DoesNotExist): try: twatch = TranslationWatch.objects.get_or_create(resource=resource, language=language)[0] result = { 'style': 'watch_remove', 'title': _('Stop watching'), 'id': twatch.id, 'url': url, 'error': None, } notification.observe(twatch, request.user, 'project_resource_translation_changed', signal='project_resource_translation_changed') except WatchException, e: return json_error(e.message, result)
for signal in resource_signals: try: notification.stop_observing(resource, request.user, signal) except notification.ObservedItem.MultipleObjectsReturned, e: notification.ObservedItem.objects.filter(user=request.user, signal=signal, content_type__model='resource', object_id=resource.id).delete() except notification.ObservedItem.DoesNotExist: try: result = { 'style': 'watch_remove', 'title': _('Stop watching this project'), 'project': True, 'url': url, 'error': None, } for signal in project_signals: notification.observe(project, request.user, signal, signal) for release in project.releases.all(): for signal in release_signals: notification.observe(release, request.user, signal, signal) for resource in project.resources.all(): for signal in resource_signals: notification.observe(resource, request.user, signal, signal) except WatchException, e: return json_error(e.message, result) return json_result(result)
def setUp(self): user = UserFactory() self.decision = DecisionFactory(author=user, description="Eat Cheese") watcher = UserFactory(email="*****@*****.**") notification.observe(self.decision, watcher, 'decision_change')
def get(self, request, *args, **kwargs): decision = self.get_object() user = self.get_user() if not notification.is_observing(decision, user): notification.observe(decision, user, DECISION_CHANGE) return HttpResponseRedirect(request.GET['next'])
def test_add_watcher_triggers_no_update(self): orig_last_modified = self.last_modified() notification.observe(self.decision, UserFactory(), DECISION_CHANGE) self.decision.save() self.assertTrue(orig_last_modified == self.last_modified())