Esempio n. 1
0
 def post_save(self, form):
     if form.is_valid() and self.mode != START:
         if self.label_id != form.cleaned_data.get('label'):
             if form.cleaned_data.get('label'):
                 labels_dict = Label.objects.get_cached_labels_dict()
                 new_label = labels_dict.get(form.cleaned_data.get('label'))
                 if new_label:
                     label_thread(self.user, self.thread, new_label)
             else:
                 unlabel_thread(self.user, self.thread)
Esempio n. 2
0
    def action_label(self, request, thread, label_slug):
        for label in self.forum.labels:
            if label.slug == label_slug:
                break
        else:
            raise moderation.ModerationError(self.invalid_action_message)

        moderation.label_thread(request.user, thread, label)
        message = _('Thread was labeled "%(label)s".')
        messages.success(request, message % {'label': label.name})
Esempio n. 3
0
    def action_label(self, request, thread, label_slug):
        for label in self.forum.labels:
            if label.slug == label_slug:
                break
        else:
            raise moderation.ModerationError(self.invalid_action_message)

        moderation.label_thread(request.user, thread, label)
        message = _('Thread was labeled "%(label)s".')
        messages.success(request, message % {'label': label.name})
Esempio n. 4
0
 def post_save(self, form):
     if form.is_valid() and self.mode != START:
         if self.label_id != form.cleaned_data.get('label'):
             if form.cleaned_data.get('label'):
                 labels_dict = Label.objects.get_cached_labels_dict()
                 new_label = labels_dict.get(form.cleaned_data.get('label'))
                 if new_label:
                     label_thread(self.user, self.thread, new_label)
             else:
                 unlabel_thread(self.user, self.thread)
Esempio n. 5
0
    def action_label(self, request, threads, label_slug):
        for label in self.forum.labels:
            if label.slug == label_slug:
                break
        else:
            raise moderation.ModerationError(self.invalid_action_message)

        changed_threads = 0
        for thread in threads:
            if moderation.label_thread(request.user, thread, label):
                changed_threads += 1

        if changed_threads:
            message = ungettext(
                '%(changed)d thread was labeled "%(label)s".',
                '%(changed)d threads were labeled "%(label)s".',
                changed_threads)
            messages.success(
                request, message % {
                    'changed': changed_threads,
                    'label': label.name
                })
        else:
            message = _("No threads were labeled.")
            messages.info(request, message)
Esempio n. 6
0
    def test_label_thread(self):
        """label_thread makes thread announcement"""
        label = Label.objects.create(name="Label", slug="label")

        self.assertIsNone(self.thread.label)
        self.assertTrue(moderation.label_thread(self.user, self.thread, label))

        self.reload_thread()
        self.assertEqual(self.thread.label, label)

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

        self.assertEqual(event.icon, "tag")
        self.assertIn("set thread label to", event.message)
Esempio n. 7
0
    def test_unlabel_thread(self):
        """unlabel_thread removes thread label"""
        label = Label.objects.create(name="Label", slug="label")
        self.assertTrue(moderation.label_thread(self.user, self.thread, label))

        self.reload_thread()
        self.assertTrue(moderation.unlabel_thread(self.user, self.thread))

        self.reload_thread()
        self.assertIsNone(self.thread.label)

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

        self.assertEqual(event.icon, "tag")
        self.assertIn("removed thread label.", event.message)
Esempio n. 8
0
    def action_label(self, request, threads, label_slug):
        for label in self.forum.labels:
            if label.slug == label_slug:
                break
        else:
            raise moderation.ModerationError(self.invalid_action_message)

        changed_threads = 0
        for thread in threads:
            if moderation.label_thread(request.user, thread, label):
                changed_threads += 1

        if changed_threads:
            message = ungettext(
                '%(changed)d thread was labeled "%(label)s".',
                '%(changed)d threads were labeled "%(label)s".',
            changed_threads)
            messages.success(request, message % {
                'changed': changed_threads,
                'label': label.name
            })
        else:
            message = _("No threads were labeled.")
            messages.info(request, message)