Example #1
0
def private_join(request, topic_id):
    # This is for topic creators who left their own topics and want to join again
    topic = get_object_or_404(
        Topic,
        pk=topic_id,
        user=request.user,
        category_id=settings.ST_TOPIC_PRIVATE_CATEGORY_PK)

    if request.method == 'POST':
        form = TopicPrivateJoinForm(topic=topic,
                                    user=request.user,
                                    data=request.POST)

        if form.is_valid():
            topic_private_access_pre_create.send(sender=TopicPrivate,
                                                 topic=topic,
                                                 user=request.user)
            form.save()

            return redirect(request.POST.get('next', topic.get_absolute_url()))
    else:
        form = TopicPrivateJoinForm()

    return render(request, 'spirit/topic_private/private_join.html', {
        'topic': topic,
        'form': form,
    })
Example #2
0
def private_access_create(request, topic_id):
    topic_private = TopicPrivate.objects.for_create_or_404(topic_id, request.user)
    form = TopicPrivateInviteForm(topic=topic_private.topic, data=request.POST)

    if form.is_valid():
        topic_private_access_pre_create.send(sender=topic_private.__class__,
                                             topic=topic_private.topic,
                                             user=form.cleaned_data['user'])
        form.save()
    else:
        messages.error(request, utils.render_form_errors(form))

    return redirect(request.POST.get('next', topic_private.get_absolute_url()))
Example #3
0
def private_join(request, topic_id):
    # This is for topic creators who left their own topics and want to join again
    topic = get_object_or_404(Topic, pk=topic_id, user=request.user, category_id=settings.ST_TOPIC_PRIVATE_CATEGORY_PK)

    if request.method == 'POST':
        form = TopicPrivateJoinForm(topic=topic, user=request.user, data=request.POST)

        if form.is_valid():
            topic_private_access_pre_create.send(sender=TopicPrivate, topic=topic, user=request.user)
            form.save()

            return redirect(request.POST.get('next', topic.get_absolute_url()))
    else:
        form = TopicPrivateJoinForm()

    return render(request, 'spirit/topic_private/private_join.html', {'topic': topic, 'form': form, })
    def test_topic_private_access_pre_create_handler(self):
        """
        create notifications on topic private access created
        """
        private = utils.create_private_topic()
        comment = utils.create_comment(topic=private.topic)
        topic_private_access_pre_create.send(sender=private.__class__,
                                             topic=private.topic,
                                             user=private.user)
        notification = TopicNotification.objects.get(user=private.user, topic=private.topic)
        self.assertEqual(notification.action, COMMENT)
        self.assertTrue(notification.is_active)
        self.assertFalse(notification.is_read)
        self.assertEqual(repr(notification.comment), repr(comment))

        # creating the access again should do nothing
        topic_private_access_pre_create.send(sender=private.__class__,
                                             topic=private.topic,
                                             user=private.user)
Example #5
0
    def test_topic_private_access_pre_create_handler(self):
        """
        create notifications on topic private access created
        """
        private = utils.create_private_topic()
        comment = utils.create_comment(topic=private.topic)
        topic_private_access_pre_create.send(sender=private.__class__,
                                             topic=private.topic,
                                             user=private.user)
        notification = TopicNotification.objects.get(user=private.user,
                                                     topic=private.topic)
        self.assertEqual(notification.action, COMMENT)
        self.assertTrue(notification.is_active)
        self.assertFalse(notification.is_read)
        self.assertEqual(repr(notification.comment), repr(comment))

        # creating the access again should do nothing
        topic_private_access_pre_create.send(sender=private.__class__,
                                             topic=private.topic,
                                             user=private.user)