def test_private_publish_topic_private_post_create_signals(self): """ send topic_private_post_create signal """ def topic_private_post_create_handler(sender, topics_private, comment, **kwargs): self.assertEqual(len(topics_private), 1) tp = topics_private[0] self._topic = repr(tp.topic) self._user = repr(tp.user) self._comment = repr(comment) topic_private_post_create.connect(topic_private_post_create_handler) utils.login(self) form_data = { 'comment': 'foo', 'title': 'foobar', 'users': self.user.username } response = self.client.post(reverse('foro:private-publish'), form_data) self.assertEqual(response.status_code, 302) topic_private = TopicPrivate.objects.last() topic_comment = Comment.objects.last() self.assertEqual(self._topic, repr(topic_private.topic)) self.assertEqual(self._user, repr(self.user)) self.assertEqual(self._comment, repr(topic_comment))
def test_private_publish_topic_private_post_create_signals(self): """ send topic_private_post_create signal """ def topic_private_post_create_handler(sender, topics_private, comment, **kwargs): self.assertEqual(len(topics_private), 1) tp = topics_private[0] self._topic = repr(tp.topic) self._user = repr(tp.user) self._comment = repr(comment) topic_private_post_create.connect(topic_private_post_create_handler) utils.login(self) form_data = {'comment': 'foo', 'title': 'foobar', 'users': self.user.username} response = self.client.post(reverse('foro:private-publish'), form_data) self.assertEqual(response.status_code, 302) topic_private = TopicPrivate.objects.last() topic_comment = Comment.objects.last() self.assertEqual(self._topic, repr(topic_private.topic)) self.assertEqual(self._user, repr(self.user)) self.assertEqual(self._comment, repr(topic_comment))
TopicNotification.objects.bulk_create([TopicNotification(user=tp.user, topic=tp.topic, comment=comment, action=COMMENT, is_active=True) for tp in topics_private if tp.user != tp.topic.user]) def topic_private_access_pre_create_handler(sender, topic, user, **kwargs): # TODO: use update_or_create on django 1.7 # change to post create try: TopicNotification.objects.create(user=user, topic=topic, comment=topic.comment_set.last(), action=COMMENT, is_active=True) except IntegrityError: pass def topic_viewed_handler(sender, request, topic, **kwargs): if not request.user.is_authenticated(): return TopicNotification.objects.filter(user=request.user, topic=topic)\ .update(is_read=True) comment_posted.connect(comment_posted_handler, dispatch_uid=__name__) topic_private_post_create.connect(topic_private_post_create_handler, dispatch_uid=__name__) topic_private_access_pre_create.connect(topic_private_access_pre_create_handler, dispatch_uid=__name__) topic_viewed.connect(topic_viewed_handler, dispatch_uid=__name__)
]) def topic_private_access_pre_create_handler(sender, topic, user, **kwargs): # TODO: use update_or_create on django 1.7 # change to post create try: TopicNotification.objects.create(user=user, topic=topic, comment=topic.comment_set.last(), action=COMMENT, is_active=True) except IntegrityError: pass def topic_viewed_handler(sender, request, topic, **kwargs): if not request.user.is_authenticated(): return TopicNotification.objects.filter(user=request.user, topic=topic)\ .update(is_read=True) comment_posted.connect(comment_posted_handler, dispatch_uid=__name__) topic_private_post_create.connect(topic_private_post_create_handler, dispatch_uid=__name__) topic_private_access_pre_create.connect( topic_private_access_pre_create_handler, dispatch_uid=__name__) topic_viewed.connect(topic_viewed_handler, dispatch_uid=__name__)