Beispiel #1
0
    def generate_calibration_report(self, appstruct, checkout_id):
        """ Use the generator object from the calibration report module
        to create a single page pdf.
        """

        report = EmptyReport()
        report.serial = appstruct["serial"]
        report.coefficient_0 = appstruct["coefficient_0"]
        report.coefficient_1 = appstruct["coefficient_1"]
        report.coefficient_2 = appstruct["coefficient_2"]
        report.coefficient_3 = appstruct["coefficient_3"]
        pdf = WasatchSinglePage(report=report, return_blob=True)

        blob_data = pdf.return_blob()
        log.info("PDF report blob: %s", len(blob_data))
        new_file = File(filename="Calibration_Report.pdf",
                        file_data=blob_data)


        dbqry = DBSession.query(Checkout)
        checkout = dbqry.filter(Checkout.id == checkout_id).one()
        checkout.files.append(new_file)

        blob_data = pdf.return_thumbnail_blob()
        self.cache_blob(blob_data, checkout_id,
                        "calibration_report_thumbnail.png")
        log.info("thumbnail report blob: %s", len(blob_data))
        new_file = File(filename="calibration_report_thumbnail.png",
                        file_data=blob_data)

        dbqry = DBSession.query(Checkout)
        checkout = dbqry.filter(Checkout.id == checkout_id).one()
        checkout.files.append(new_file)
    def test_fully_valid_report(self):
        from calibrationreport.models import EmptyReport
        from calibrationreport.pdfgenerator import WasatchSinglePage 

        filename = "with_images_check.pdf"
        self.assertFalse(touch_erase(filename))

        img0 = "resources/image0_defined.jpg"
        img1 = "resources/image1_defined.jpg"

        report = EmptyReport()
        report.serial = "DEFINEDSERIAL01234"
        report.coeff_0 = "1000.1213123*e-06"
        report.coeff_1 = "1001.1213123*e-06"
        report.coeff_2 = "1002.1213123*e-06"
        report.coeff_3 = "1003.1213123*e-06"
        report.top_image_filename = img0
        report.bottom_image_filename = img1
        pdf = WasatchSinglePage(filename=filename, report=report)
        self.assertTrue(file_range(filename, 106494))
    def populate_data(self, appstruct):
        """ Convenience function to fill the data has with the values
        from the POST'ed form.
        """ 
        local = EmptyReport()
        local.serial = appstruct["serial"]
        local.slugged = slugify(appstruct["serial"])
        local.filename = "reports/%s/report.pdf" % local.slugged
        local.coefficient_0 = appstruct["coefficient_0"]
        local.coefficient_1 = appstruct["coefficient_1"]
        local.coefficient_2 = appstruct["coefficient_2"]
        local.coefficient_3 = appstruct["coefficient_3"]

        # Images are optional, set to placeholder if not specified
        if appstruct["top_image_upload"] == colander.null:
            local.top_image_filename = "resources/image0_defined.jpg"
        else:
            local.top_image_filename = "reports/%s/top_image.png" \
                                       % local.slugged

        if appstruct["bottom_image_upload"] == colander.null:
            local.bottom_image_filename = "resources/image1_defined.jpg"
        else:
            local.bottom_image_filename = "reports/%s/bottom_image.png" \
                                          % local.slugged
  

        return local