Exemplo n.º 1
0
    def test_private_join_access_pre_create_signal(self):
        """
        send topic_private_access_pre_create signal
        """
        def topic_private_access_pre_create_handler(sender, topic, user,
                                                    **kwargs):
            self._topic = repr(topic)
            self._user_pk = user.pk

        topic_private_access_pre_create.connect(
            topic_private_access_pre_create_handler)

        private = utils.create_private_topic(user=self.user)
        private.delete()

        utils.login(self)
        form_data = {}
        response = self.client.post(
            reverse('foro:private-join',
                    kwargs={
                        'topic_id': private.topic.pk,
                    }), form_data)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(self._topic, repr(private.topic))
        self.assertEqual(self._user_pk, self.user.pk)
Exemplo n.º 2
0
    def test_private_access_create_pre_create_signal(self):
        """
        send topic_private_access_pre_create signal
        """
        def topic_private_access_pre_create_handler(sender, topic, user,
                                                    **kwargs):
            self._topic = repr(topic)
            self._user = repr(user)

        topic_private_access_pre_create.connect(
            topic_private_access_pre_create_handler)

        utils.login(self)
        private = utils.create_private_topic(user=self.user)
        form_data = {
            'user': self.user2.username,
        }
        response = self.client.post(
            reverse('foro:private-access-create',
                    kwargs={
                        'topic_id': private.topic.pk,
                    }), form_data)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(self._topic, repr(private.topic))
        self.assertEqual(self._user, repr(self.user2))
Exemplo n.º 3
0
    def test_private_access_create_pre_create_signal(self):
        """
        send topic_private_access_pre_create signal
        """
        def topic_private_access_pre_create_handler(sender, topic, user, **kwargs):
            self._topic = repr(topic)
            self._user = repr(user)
        topic_private_access_pre_create.connect(topic_private_access_pre_create_handler)

        utils.login(self)
        private = utils.create_private_topic(user=self.user)
        form_data = {'user': self.user2.username, }
        response = self.client.post(reverse('foro:private-access-create', kwargs={'topic_id': private.topic.pk, }),
                                    form_data)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(self._topic, repr(private.topic))
        self.assertEqual(self._user, repr(self.user2))
Exemplo n.º 4
0
    def test_private_join_access_pre_create_signal(self):
        """
        send topic_private_access_pre_create signal
        """
        def topic_private_access_pre_create_handler(sender, topic, user, **kwargs):
            self._topic = repr(topic)
            self._user_pk = user.pk
        topic_private_access_pre_create.connect(topic_private_access_pre_create_handler)

        private = utils.create_private_topic(user=self.user)
        private.delete()

        utils.login(self)
        form_data = {}
        response = self.client.post(reverse('foro:private-join', kwargs={'topic_id': private.topic.pk, }),
                                    form_data)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(self._topic, repr(private.topic))
        self.assertEqual(self._user_pk, self.user.pk)
Exemplo n.º 5
0
    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__)
Exemplo n.º 6
0
    ])


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__)