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)
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)
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."))
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)
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)
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')
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")
def action_open(self, request, thread): moderation.open_thread(request.user, thread) messages.success(request, _("Thread was opened."))
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))
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))