def after_thread_action_normal(self): self.thread.set_checkpoint(self.request, 'bogus') if self.thread.original_weight == 2: with UpdatingMonitor() as cm: monitor.decrease('reported_posts') messages.success(self.request, _('Report has been set as bogus.'), 'threads')
def post_form(self, form): self.thread.original_weight = self.thread.weight super(SetStateCheckpointMixin, self).post_form(form) if self.thread.original_weight != self.thread.weight: if self.thread.original_weight == 2: with UpdatingMonitor() as cm: monitor.decrease('reported_posts') if self.thread.weight == 1: self.thread.set_checkpoint(self.request, 'resolved') if self.thread.weight == 0: self.thread.set_checkpoint(self.request, 'bogus')
def thread_action_hard(self): # Delete thread self.thread.delete() # Update forum self.forum.sync() self.forum.save(force_update=True) # Update monitor with UpdatingMonitor() as cm: monitor.decrease('threads') monitor.decrease('posts', self.thread.replies + 1) self.after_thread_action_hard() return self.threads_list_redirect()
def action_activate(self, items, checked): for user in items: if user.pk in checked and user.activation > 0: with UpdatingMonitor() as cm: monitor.decrease('users_inactive') user.activation = user.ACTIVATION_NONE user.save(force_update=True) user.email_user( self.request, 'users/activation/admin_done', _("Your Account has been activated"), ) return Message(_('Selected users accounts have been activated.'), messages.SUCCESS), reverse('admin_users')
def thread_action_soft(self): # Update first post in thread self.thread.start_post.deleted = True self.thread.start_post.save(force_update=True) # Update thread self.thread.sync() self.thread.save(force_update=True) # Set checkpoint self.thread.set_checkpoint(self.request, 'deleted') # Update forum self.forum.sync() self.forum.save(force_update=True) # Update monitor with UpdatingMonitor() as cm: monitor.decrease('threads') monitor.decrease('posts', self.thread.replies + 1) self.after_thread_action_soft()
def mass_resolve(self, ids): reported_posts = [] reported_threads = [] for thread in self.threads: if thread.pk in ids: if thread.original_weight != thread.weight: if thread.weight == 1: thread.set_checkpoint(self.request, 'resolved') if thread.weight == 0: thread.set_checkpoint(self.request, 'bogus') if thread.original_weight == 2 and thread.report_for_id: reported_posts.append(thread.report_for.pk) reported_threads.append(thread.report_for.thread_id) if reported_threads: Thread.objects.filter(id__in=reported_threads).update(replies_reported=F('replies_reported') - 1) Post.objects.filter(id__in=reported_posts).update(reported=False, reports=None) with UpdatingMonitor() as cm: monitor.decrease('reported_posts', len(reported_threads))
def thread_action_soft(self): # Update first post in thread self.thread.start_post.deleted = True self.thread.start_post.edit_user = self.request.user self.thread.start_post.edit_user_name = self.request.user.username self.thread.start_post.edit_user_slug = self.request.user.username_slug self.thread.start_post.save(force_update=True) # Update thread self.thread.sync() self.thread.save(force_update=True) # Set checkpoint self.thread.set_checkpoint(self.request, 'deleted') # Update forum self.forum.sync() self.forum.save(force_update=True) # Update monitor with UpdatingMonitor() as cm: monitor.decrease('threads') monitor.decrease('posts', self.thread.replies + 1) self.after_thread_action_soft()
def after_thread_action_soft(self): if self.thread.original_weight == 2: with UpdatingMonitor() as cm: monitor.decrease("reported_posts") messages.success(self.request, _("Report has been hidden."), "threads")
def after_thread_action_normal(self): self.thread.set_checkpoint(self.request, "bogus") if self.thread.original_weight == 2: with UpdatingMonitor() as cm: monitor.decrease("reported_posts") messages.success(self.request, _("Report has been set as bogus."), "threads")
def after_thread_action_soft(self): if self.thread.original_weight == 2: with UpdatingMonitor() as cm: monitor.decrease('reported_posts') messages.success(self.request, _('Report has been hidden.'), 'threads')