Beispiel #1
0
    def action_move(self, request, thread):
        form = MoveThreadForm(acl=request.user.acl, forum=self.forum)

        if request.method == "POST" and 'submit' in request.POST:
            form = MoveThreadForm(request.POST,
                                  acl=request.user.acl,
                                  forum=self.forum)
            if form.is_valid():
                new_forum = form.cleaned_data['new_forum']

                with atomic():
                    self.forum.lock()
                    moderation.move_thread(request.user, thread, new_forum)
                    self.forum.synchronize()
                    self.forum.save()
                    new_forum.synchronize()
                    new_forum.save()

                message = _('Thread was moved to "%(forum)s".')
                messages.success(request, message % {'forum': new_forum.name})

                return None  # trigger thread refresh

        if request.is_ajax():
            template = self.move_thread_modal_template
        else:
            template = self.move_thread_full_template

        return render(
            request, template, {
                'form': form,
                'forum': self.forum,
                'path': get_forum_path(self.forum),
                'thread': thread
            })
Beispiel #2
0
    def action_move(self, request, thread):
        form = MoveThreadForm(acl=request.user.acl, forum=self.forum)

        if request.method == "POST" and 'submit' in request.POST:
            form = MoveThreadForm(
                request.POST, acl=request.user.acl, forum=self.forum)
            if form.is_valid():
                new_forum = form.cleaned_data['new_forum']

                with atomic():
                    self.forum.lock()
                    moderation.move_thread(request.user, thread, new_forum)
                    self.forum.synchronize()
                    self.forum.save()
                    new_forum.synchronize()
                    new_forum.save()

                message = _('Thread was moved to "%(forum)s".')
                messages.success(request, message % {
                    'forum': new_forum.name
                })

                return None # trigger thread refresh

        if request.is_ajax():
            template = self.move_thread_modal_template
        else:
            template = self.move_thread_full_template

        return render(request, template, {
            'form': form,
            'forum': self.forum,
            'path': get_forum_path(self.forum),
            'thread': thread
        })
Beispiel #3
0
    def test_thread_move_event_renders(self):
        """moved thread event renders"""
        self.thread.category = self.thread.category.parent
        self.thread.save()

        moderation.move_thread(MockRequest(self.user), self.thread, self.category)

        event = self.thread.post_set.filter(is_event=True)[0]
        self.assertEqual(event.event_type, 'moved')

        # event renders
        response = self.client.get(self.thread.get_absolute_url())
        self.assertContains(response, event.get_absolute_url())
        self.assertContains(response, "Thread has been moved from")
    def test_move_thread_to_same_category(self):
        """moves_thread does not move thread to same category it is in"""
        self.assertEqual(self.thread.category, self.category)
        self.assertFalse(moderation.move_thread(self.request, self.thread, self.category))

        self.reload_thread()
        self.assertEqual(self.thread.category, self.category)
    def test_move_thread_to_same_category(self):
        """moves_thread does not move thread to same category it is in"""
        self.assertEqual(self.thread.category, self.category)
        self.assertFalse(
            moderation.move_thread(self.user, self.thread, self.category))

        self.reload_thread()
        self.assertEqual(self.thread.category, self.category)
        self.assertFalse(self.thread.has_events)
Beispiel #6
0
    def test_move_thread_to_same_forum(self):
        """moves_thread does not move thread to same forum it is in"""
        self.assertEqual(self.thread.forum, self.forum)
        self.assertFalse(
            moderation.move_thread(self.user, self.thread, self.forum))

        self.reload_thread()
        self.assertEqual(self.thread.forum, self.forum)
        self.assertFalse(self.thread.has_events)
Beispiel #7
0
    def action_move(self, request, threads):
        form = MoveThreadsForm(acl=request.user.acl, forum=self.forum)

        if 'submit' in request.POST:
            form = MoveThreadsForm(
                request.POST, acl=request.user.acl, forum=self.forum)
            if form.is_valid():
                new_forum = form.cleaned_data['new_forum']
                with atomic():

                    for thread in threads:
                        moderation.move_thread(request.user, thread, new_forum)

                    self.forum.lock()
                    new_forum.lock()

                    self.forum.synchronize()
                    self.forum.save()
                    new_forum.synchronize()
                    new_forum.save()

                changed_threads = len(threads)
                message = ungettext(
                    '%(changed)d thread was moved to "%(forum)s".',
                    '%(changed)d threads were moved to "%(forum)s".',
                changed_threads)
                messages.success(request, message % {
                    'changed': changed_threads,
                    'forum': new_forum.name
                })

                return None # trigger threads list refresh

        if request.is_ajax():
            template = self.move_threads_modal_template
        else:
            template = self.move_threads_full_template

        return render(request, template, {
            'form': form,
            'forum': self.forum,
            'path': get_forum_path(self.forum),
            'threads': threads
        })
Beispiel #8
0
def patch_move(request, thread, value):
    allow_move_thread(request.user, thread)

    category_pk = get_int_or_404(value)
    new_category = get_object_or_404(
        Category.objects.all_categories().select_related('parent'), pk=category_pk
    )

    add_acl(request.user, new_category)
    allow_see_category(request.user, new_category)
    allow_browse_category(request.user, new_category)
    allow_start_thread(request.user, new_category)

    if new_category == thread.category:
        raise ValidationError(_("You can't move thread to the category it's already in."))

    moderation.move_thread(request, thread, new_category)

    return {'category': CategorySerializer(new_category).data}
Beispiel #9
0
    def test_move_thread(self):
        """moves_thread moves moderated thread to other froum"""
        new_forum = Forum.objects.all_forums().filter(role="category")[:1][0]

        self.assertEqual(self.thread.forum, self.forum)
        self.assertTrue(
            moderation.move_thread(self.user, self.thread, new_forum))

        self.reload_thread()
        self.assertEqual(self.thread.forum, new_forum)
        self.assertTrue(self.thread.has_events)
        event = self.thread.event_set.last()

        self.assertIn("moved thread", event.message)
        self.assertEqual(event.icon, "arrow-right")
Beispiel #10
0
    def test_move_thread(self):
        """moves_thread moves unapproved thread to other category"""
        root_category = Category.objects.root_category()
        Category(
            name='New Category',
            slug='new-category',
        ).insert_at(root_category, position='last-child', save=True)
        new_category = Category.objects.get(slug='new-category')

        self.assertEqual(self.thread.category, self.category)
        self.assertTrue(
            moderation.move_thread(self.request, self.thread, new_category))

        self.reload_thread()
        self.assertEqual(self.thread.category, new_category)

        event = self.thread.last_post

        self.assertTrue(event.is_event)
        self.assertEqual(event.event_type, 'moved')
    def test_move_thread(self):
        """moves_thread moves unapproved thread to other category"""
        root_category = Category.objects.root_category()
        Category(
            name='New Category',
            slug='new-category',
        ).insert_at(root_category, position='last-child', save=True)
        new_category = Category.objects.get(slug='new-category')

        self.assertEqual(self.thread.category, self.category)
        self.assertTrue(
            moderation.move_thread(self.user, self.thread, new_category))

        self.reload_thread()
        self.assertEqual(self.thread.category, new_category)
        self.assertTrue(self.thread.has_events)
        event = self.thread.event_set.last()

        self.assertIn("moved thread", event.message)
        self.assertEqual(event.icon, "arrow-right")