Esempio n. 1
0
    def submit(self, contact_info=None, no_proxy=False):
        """Submit a composer to create the requests"""
        # pylint: disable=import-outside-toplevel
        from muckrock.foia.tasks import composer_create_foias, composer_delayed_submit

        num_requests = self.agencies.count()
        request_count = self.organization.make_requests(num_requests)
        self.num_reg_requests = request_count["regular"]
        self.num_monthly_requests = request_count["monthly"]
        self.status = "submitted"
        self.datetime_submitted = timezone.now()
        self.save()

        if num_requests == 1:
            # if only one request, create it immediately so we can redirect there
            composer_create_foias(self.pk, contact_info, no_proxy)
        else:
            # otherwise do it delayed so the page doesn't risk timing out
            composer_create_foias.delay(self.pk, contact_info, no_proxy)

        # if num_requests is less than the multi-review amount, we will approve
        # the request right away, other wise we create a multirequest task
        # if the request contains a moderated keyword, it will also not be
        # approved
        approve = (num_requests < settings.MULTI_REVIEW_AMOUNT
                   and not self.needs_moderation())
        result = composer_delayed_submit.apply_async(
            args=(self.pk, approve, contact_info),
            countdown=COMPOSER_SUBMIT_DELAY)
        self.delayed_id = result.id
        self.save()
Esempio n. 2
0
    def submit(self, contact_info=None):
        """Submit a composer to create the requests"""
        from muckrock.foia.tasks import composer_create_foias, composer_delayed_submit

        num_requests = self.agencies.count()
        request_count = self.user.profile.make_requests(num_requests)
        self.num_reg_requests = request_count['regular']
        self.num_monthly_requests = request_count['monthly']
        self.num_org_requests = request_count['org']
        self.status = 'submitted'
        self.datetime_submitted = timezone.now()

        if num_requests == 1:
            # if only one request, create it immediately so we can redirect there
            composer_create_foias(self.pk, contact_info)
        else:
            # otherwise do it delayed so the page doesn't risk timing out
            composer_create_foias.delay(self.pk, contact_info)

        # if num_requests is less than the multi-review amount, we will approve
        # the request right away, other wise we create a multirequest task
        approve = num_requests < settings.MULTI_REVIEW_AMOUNT
        result = composer_delayed_submit.apply_async(
            args=(self.pk, approve, contact_info),
            countdown=COMPOSER_SUBMIT_DELAY,
        )
        self.delayed_id = result.id
        self.save()
Esempio n. 3
0
 def submit(self, agency_list):
     """Submit the composer"""
     # pylint: disable=not-callable
     from muckrock.foia.tasks import composer_delayed_submit
     return_requests = 0
     with transaction.atomic():
         for agency in self.composer.agencies.all():
             if str(agency.pk) not in agency_list:
                 self.composer.agencies.remove(agency)
                 self.composer.foias.filter(agency=agency).delete()
                 return_requests += 1
         self.composer.return_requests(return_requests)
         transaction.on_commit(lambda: composer_delayed_submit.apply_async(
             args=(self.composer.pk, True, None)))