예제 #1
0
    def _build_return_value(self, schema, appstruct, query):
        """
        Return the streamed file object
        """
        all_ids = [elem.id for elem in query]
        logger.debug("    + All_ids where collected : {0}".format(all_ids))
        service_ok, msg = check_alive()
        if not service_ok:
            if "popup" in self.request.GET:
                set_close_popup_response(self.request, error=msg)
                return self.request.response
            else:
                self.request.session.flash(msg, 'error')
                return HTTPFound(self.request.referrer)

        logger.debug("    + In the GlobalInvoicesCsvView._build_return_value")
        job = FileGenerationJob()
        job.set_owner(self.request.user.login.login)
        self.request.dbsession.add(job)
        self.request.dbsession.flush()
        logger.debug("    + The job {job.id} was initialized".format(job=job))
        logger.debug("    + Delaying the export_to_file task")
        celery_job = export_to_file.delay(job.id, 'invoices', all_ids,
                                          self.filename, self.file_format)
        logger.info(u"The Celery Task {0} has been delayed, its result "
                    "sould be retrieved from the FileGenerationJob {1}".format(
                        celery_job.id, job.id))

        return HTTPFound(
            self.request.route_path('job', id=job.id, _query={'popup': 1}))
예제 #2
0
    def _build_return_value(self, schema, appstruct, query):
        """
        Return the streamed file object
        """
        all_ids = [elem[0] for elem in query]

        if not all_ids:
            msg = u"Il n'y a aucun élément à exporter"
            set_close_popup_response(self.request, msg)
            return self.request.response

        job = FileGenerationJob()
        job.set_owner(self.request.user.login.login)
        self.request.dbsession.add(job)
        self.request.dbsession.flush()
        celery_job = export_to_file.delay(
            job.id,
            'userdatas',
            all_ids,
            self.filename,
            self.file_format
        )

        logger.info(
            u"The Celery Task {0} has been delayed, its result "
            "sould be retrieved from the FileGenerationJob {1}".format(
                celery_job.id, job.id
            )
        )

        return HTTPFound(
            self.request.route_path('job', id=job.id, _query={'popup': 1})
        )
예제 #3
0
    def _build_return_value(self, schema, appstruct, query):
        """
        Return the streamed file object
        """
        all_ids = [elem.id for elem in query]
        logger.debug("    + All_ids where collected : {0}".format(all_ids))
        service_ok, msg = check_alive()
        if not service_ok:
            if "popup" in self.request.GET:
                set_close_popup_response(self.request, error=msg)
                return self.request.response
            else:
                self.request.session.flash(msg, 'error')
                return HTTPFound(self.request.referrer)

        logger.debug("    + In the GlobalInvoicesCsvView._build_return_value")
        job = FileGenerationJob()
        job.set_owner(self.request.user.login.login)
        self.request.dbsession.add(job)
        self.request.dbsession.flush()
        logger.debug("    + The job {job.id} was initialized".format(job=job))
        logger.debug("    + Delaying the export_to_file task")
        celery_job = export_to_file.delay(
            job.id,
            'invoices',
            all_ids,
            self.filename,
            self.file_format
        )
        logger.info(
            u"The Celery Task {0} has been delayed, its result "
            "sould be retrieved from the FileGenerationJob {1}".format(
                celery_job.id, job.id
            )
        )

        return HTTPFound(
            self.request.route_path('job', id=job.id, _query={'popup': 1})
        )