Beispiel #1
0
def private_publish(request, user_id=None):
    if request.method == 'POST':
        tform = TopicForPrivateForm(user=request.user, data=request.POST)
        cform = CommentForm(user=request.user, data=request.POST)
        tpform = TopicPrivateManyForm(user=request.user, data=request.POST)

        if not request.is_limited and tform.is_valid() and cform.is_valid() and tpform.is_valid():
            # wrap in transaction.atomic?
            topic = tform.save()
            cform.topic = topic
            comment = cform.save()
            comment_posted.send(sender=comment.__class__, comment=comment, mentions=None)
            tpform.topic = topic
            topics_private = tpform.save_m2m()
            topic_private_post_create.send(sender=TopicPrivate, topics_private=topics_private, comment=comment)
            return redirect(topic.get_absolute_url())

    else:
        tform = TopicForPrivateForm()
        cform = CommentForm()
        initial = None

        if user_id:
            user = get_object_or_404(User, pk=user_id)
            initial = {'users': [user.username, ]}

        tpform = TopicPrivateManyForm(initial=initial)

    return render(request, 'spirit/topic_private/private_publish.html', {'tform': tform,
                                                                         'cform': cform,
                                                                         'tpform': tpform})
 def test_topic_private_post_create_handler(self):
     """
     create notifications on topic private created
     """
     private = utils.create_private_topic()
     private2 = TopicPrivate.objects.create(user=self.user, topic=private.topic)
     comment = utils.create_comment(topic=private.topic)
     topic_private_post_create.send(sender=private.__class__,
                                    topics_private=[private, private2],
                                    comment=comment)
     self.assertEqual(len(TopicNotification.objects.filter(user=private.user, topic=private.topic)), 0)
     notification = TopicNotification.objects.get(user=private2.user, topic=private2.topic)
     self.assertTrue(notification.is_active)
     self.assertFalse(notification.is_read)
     self.assertEqual(repr(notification.comment), repr(comment))
Beispiel #3
0
 def test_topic_private_post_create_handler(self):
     """
     create notifications on topic private created
     """
     private = utils.create_private_topic()
     private2 = TopicPrivate.objects.create(user=self.user,
                                            topic=private.topic)
     comment = utils.create_comment(topic=private.topic)
     topic_private_post_create.send(sender=private.__class__,
                                    topics_private=[private, private2],
                                    comment=comment)
     self.assertEqual(
         len(
             TopicNotification.objects.filter(user=private.user,
                                              topic=private.topic)), 0)
     notification = TopicNotification.objects.get(user=private2.user,
                                                  topic=private2.topic)
     self.assertTrue(notification.is_active)
     self.assertFalse(notification.is_read)
     self.assertEqual(repr(notification.comment), repr(comment))