Esempio n. 1
0
 def post_save(self, form):
     if form.is_valid() and self.mode != START:
         if self.is_closed != form.cleaned_data.get('is_closed'):
             if self.thread.is_closed:
                 moderation.open_thread(self.user, self.thread)
             else:
                 moderation.close_thread(self.user, self.thread)
Esempio n. 2
0
 def post_save(self, form):
     if form.is_valid() and self.mode != START:
         if self.thread_is_closed != form.cleaned_data.get('is_closed'):
             if self.thread.is_closed:
                 moderation.open_thread(self.user, self.thread)
             else:
                 moderation.close_thread(self.user, self.thread)
Esempio n. 3
0
def patch_is_closed(request, thread, value):
    if thread.acl.get('can_close'):
        if value:
            moderation.close_thread(request, thread)
        else:
            moderation.open_thread(request, thread)

        return {'is_closed': thread.is_closed}
    else:
        if value:
            raise PermissionDenied(_("You don't have permission to close this thread."))
        else:
            raise PermissionDenied(_("You don't have permission to open this thread."))
Esempio n. 4
0
    def action_open(self, request, threads):
        changed_threads = 0
        for thread in threads:
            if moderation.open_thread(request.user, thread):
                changed_threads += 1

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

        if changed_threads:
            message = ungettext(
                '%(changed)d thread was opened.',
                '%(changed)d threads were opened.',
            changed_threads)
            messages.success(request, message % {'changed': changed_threads})
        else:
            message = _("No threads were opened.")
            messages.info(request, message)
Esempio n. 6
0
    def test_open_thread(self):
        """open_thread closes thread"""
        moderation.close_thread(self.request, self.thread)
        self.reload_thread()

        self.assertTrue(self.thread.is_closed)
        self.assertTrue(moderation.open_thread(self.request, self.thread))

        self.reload_thread()
        self.assertFalse(self.thread.is_closed)

        event = self.thread.last_post

        self.assertTrue(event.is_event)
        self.assertEqual(event.event_type, 'opened')
Esempio n. 7
0
    def test_open_thread(self):
        """open_thread closes thread"""
        moderation.close_thread(self.user, self.thread)
        self.reload_thread()

        self.assertTrue(self.thread.is_closed)
        self.assertTrue(moderation.open_thread(self.user, self.thread))

        self.reload_thread()
        self.assertFalse(self.thread.is_closed)
        self.assertTrue(self.thread.has_events)
        event = self.thread.event_set.last()

        self.assertIn("opened thread.", event.message)
        self.assertEqual(event.icon, "unlock-alt")
Esempio n. 8
0
 def action_open(self, request, thread):
     moderation.open_thread(request.user, thread)
     messages.success(request, _("Thread was opened."))
Esempio n. 9
0
 def test_open_invalid_thread(self):
     """open_thread fails gracefully for opened thread"""
     self.assertFalse(self.thread.is_closed)
     self.assertFalse(moderation.open_thread(self.request, self.thread))
Esempio n. 10
0
 def test_open_invalid_thread(self):
     """open_thread fails gracefully for opened thread"""
     self.assertFalse(self.thread.is_closed)
     self.assertFalse(moderation.open_thread(self.user, self.thread))
Esempio n. 11
0
 def action_open(self, request, thread):
     moderation.open_thread(request.user, thread)
     messages.success(request, _("Thread was opened."))