コード例 #1
0
def user_suspended_delete_emails(kwargs,
                                 batch_number=500,
                                 chunk_size=10000,
                                 delay=20):
    kwargs = {"inbox__user__%s" % k: v for k, v in kwargs.items()}
    emails = create_queryset("email", kwargs=kwargs)
    for idx, chunk in chunk_queryset(emails, chunk_size):
        email_tasks = delete_inboxen_item.chunks([("email", i) for i in chunk],
                                                 batch_number).group()
        task_group_skew(email_tasks, start=(idx + 1) * delay, step=delay)
        email_tasks.delay()
コード例 #2
0
ファイル: inbox.py プロジェクト: wrestrtdr/Inboxen
    def post(self, *args, **kwargs):
        qs = self.get_queryset()

        # this is kinda bad, but nested forms aren't supported in all browsers
        if "delete-single" in self.request.POST:
            try:
                email_id = int(self.request.POST["delete-single"], 16)
                email = qs.get(id=email_id)
            except (self.model.DoesNotExist, ValueError):
                raise Http404

            email.delete()

            return HttpResponseRedirect(self.get_success_url())
        elif "important-single" in self.request.POST:
            try:
                email_id = int(self.request.POST["important-single"], 16)
                email = qs.get(id=email_id)
            except (self.model.DoesNotExist, ValueError):
                raise Http404

            email.important = not email.important
            email.save(update_fields=["important"])

            return HttpResponseRedirect(self.get_success_url())

        emails = []
        for email in self.request.POST:
            if self.request.POST[email] == "email":
                try:
                    email_id = int(email, 16)
                    emails.append(email_id)
                except ValueError:
                    raise Http404

        if len(emails) == 0:
            # nothing was selected, return early
            return HttpResponseRedirect(self.get_success_url())

        qs = qs.filter(id__in=emails).order_by("id")
        if "unimportant" in self.request.POST:
            qs.update(important=False)
        elif "important" in self.request.POST:
            qs.update(important=True)
        elif "delete" in self.request.POST:
            email_ids = [("email", email.id) for email in qs]
            qs.update(deleted=True)
            delete_task = delete_inboxen_item.chunks(email_ids, 500).group()
            task_group_skew(delete_task, step=50)
            delete_task.apply_async()

        return HttpResponseRedirect(self.get_success_url())