Exemplo n.º 1
0
 def post_save(self, form):
     if form.is_valid() and self.mode != START:
         if self.is_pinned != form.cleaned_data.get('is_pinned'):
             if self.thread.is_pinned:
                 moderation.unpin_thread(self.user, self.thread)
             else:
                 moderation.pin_thread(self.user, self.thread)
Exemplo n.º 2
0
    def test_unpin_thread(self):
        """unpin_thread defaults thread weight"""
        moderation.pin_thread(self.user, self.thread)

        self.assertTrue(self.thread.is_pinned)
        self.assertTrue(moderation.unpin_thread(self.user, self.thread))

        self.reload_thread()
        self.assertFalse(self.thread.is_pinned)

        self.assertTrue(self.thread.has_events)
        event = self.thread.event_set.last()

        self.assertIn("unpinned thread.", event.message)
        self.assertEqual(event.icon, "circle")
Exemplo n.º 3
0
    def test_pin_thread(self):
        """pin_thread makes thread pinned"""
        self.assertFalse(self.thread.is_pinned)
        self.assertTrue(moderation.pin_thread(self.user, self.thread))

        self.reload_thread()
        self.assertTrue(self.thread.is_pinned)

        self.assertTrue(self.thread.has_events)
        event = self.thread.event_set.last()

        self.assertEqual(event.icon, "star")
        self.assertIn("pinned thread.", event.message)
Exemplo n.º 4
0
    def action_pin(self, request, threads):
        changed_threads = 0
        for thread in threads:
            if moderation.pin_thread(request.user, thread):
                changed_threads += 1

        if changed_threads:
            message = ungettext('%(changed)d thread was pinned.',
                                '%(changed)d threads were pinned.',
                                changed_threads)
            messages.success(request, message % {'changed': changed_threads})
        else:
            message = _("No threads were pinned.")
            messages.info(request, message)
Exemplo n.º 5
0
    def action_pin(self, request, threads):
        changed_threads = 0
        for thread in threads:
            if moderation.pin_thread(request.user, thread):
                changed_threads += 1

        if changed_threads:
            message = ungettext(
                '%(changed)d thread was pinned.',
                '%(changed)d threads were pinned.',
            changed_threads)
            messages.success(request, message % {'changed': changed_threads})
        else:
            message = _("No threads were pinned.")
            messages.info(request, message)
Exemplo n.º 6
0
 def action_pin(self, request, thread):
     moderation.pin_thread(request.user, thread)
     messages.success(request, _("Thread was pinned."))
Exemplo n.º 7
0
 def action_pin(self, request, thread):
     moderation.pin_thread(request.user, thread)
     messages.success(request, _("Thread was pinned."))
Exemplo n.º 8
0
    def test_pin_invalid_thread(self):
        """pin_thread returns false for already pinned thread"""
        self.thread.is_pinned = True

        self.assertFalse(moderation.pin_thread(self.user, self.thread))
        self.assertTrue(self.thread.is_pinned)